ML Kit FaceDetection CameraSourcePreview is null





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have implemented the Firebase ML Kit for face-detection in my app. In the demo app, where I created a new Firebase project and added the google json file its working fine. But in the existing app (the one on the playstore app) it returns null for the CameraSourcePreview and graphicOverlay declaration. Below is the code that I am using in my app:



public class ChildModeActivity extends BaseActivity {
private CameraSource cameraSource = null;
private CameraSourcePreview preview;
private GraphicOverlay graphicOverlay;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_child_mode);
preview = (CameraSourcePreview) findViewById(R.id.childCameraPreview);
if (preview == null) {
Log.d("TAG_FACE", "Preview is null");
}
graphicOverlay = (GraphicOverlay) findViewById(R.id.childFaceOverlay);
if (graphicOverlay == null) {
Log.d("TAG_FACE", "graphicOverlay is null");
}
if (allPermissionsGranted()) {
createCameraSource();
} else {
getRuntimePermissions();
}
}
private void startCameraSource() {
if (cameraSource != null) {
try {
if (preview == null) {
Log.d("TAG_FACE", "resume: Preview is null");
}
if (graphicOverlay == null) {
Log.d("TAG_FACE", "resume: graphOverlay is null");
}
preview.start(cameraSource, graphicOverlay);
} catch (IOException e) {
Log.e("TAG_FACE", "Unable to start camera source.", e);
cameraSource.release();
cameraSource = null;
}
}
}

private void createCameraSource() {
try {
// If there's no existing cameraSource, create one.
if (cameraSource == null) {
Log.i("TAG_FACE", "Camera Source is Null so create new one");
cameraSource = new CameraSource(this, graphicOverlay);
cameraSource.setFacing(CameraSource.CAMERA_FACING_FRONT);
// cameraSource = new CameraSource(this);
cameraSource.setMachineLearningFrameProcessor(new FaceDetectionProcessor());
}
}catch (Exception e){
Log.i("TAG_FACE" , " Create Camera Source Exception:" + e.getMessage());
}
}


In the above code my BaseActivity extends AppCompatActivity.



Whenever I run the app, I am getting that "Preview is null" and "graphicOverlay is null" in the log. The preview is not showing.










share|improve this question

























  • Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

    – Nathiya
    Dec 8 '18 at 12:57











  • I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

    – Nathiya
    Dec 8 '18 at 12:59


















1















I have implemented the Firebase ML Kit for face-detection in my app. In the demo app, where I created a new Firebase project and added the google json file its working fine. But in the existing app (the one on the playstore app) it returns null for the CameraSourcePreview and graphicOverlay declaration. Below is the code that I am using in my app:



public class ChildModeActivity extends BaseActivity {
private CameraSource cameraSource = null;
private CameraSourcePreview preview;
private GraphicOverlay graphicOverlay;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_child_mode);
preview = (CameraSourcePreview) findViewById(R.id.childCameraPreview);
if (preview == null) {
Log.d("TAG_FACE", "Preview is null");
}
graphicOverlay = (GraphicOverlay) findViewById(R.id.childFaceOverlay);
if (graphicOverlay == null) {
Log.d("TAG_FACE", "graphicOverlay is null");
}
if (allPermissionsGranted()) {
createCameraSource();
} else {
getRuntimePermissions();
}
}
private void startCameraSource() {
if (cameraSource != null) {
try {
if (preview == null) {
Log.d("TAG_FACE", "resume: Preview is null");
}
if (graphicOverlay == null) {
Log.d("TAG_FACE", "resume: graphOverlay is null");
}
preview.start(cameraSource, graphicOverlay);
} catch (IOException e) {
Log.e("TAG_FACE", "Unable to start camera source.", e);
cameraSource.release();
cameraSource = null;
}
}
}

private void createCameraSource() {
try {
// If there's no existing cameraSource, create one.
if (cameraSource == null) {
Log.i("TAG_FACE", "Camera Source is Null so create new one");
cameraSource = new CameraSource(this, graphicOverlay);
cameraSource.setFacing(CameraSource.CAMERA_FACING_FRONT);
// cameraSource = new CameraSource(this);
cameraSource.setMachineLearningFrameProcessor(new FaceDetectionProcessor());
}
}catch (Exception e){
Log.i("TAG_FACE" , " Create Camera Source Exception:" + e.getMessage());
}
}


In the above code my BaseActivity extends AppCompatActivity.



Whenever I run the app, I am getting that "Preview is null" and "graphicOverlay is null" in the log. The preview is not showing.










share|improve this question

























  • Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

    – Nathiya
    Dec 8 '18 at 12:57











  • I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

    – Nathiya
    Dec 8 '18 at 12:59














1












1








1








I have implemented the Firebase ML Kit for face-detection in my app. In the demo app, where I created a new Firebase project and added the google json file its working fine. But in the existing app (the one on the playstore app) it returns null for the CameraSourcePreview and graphicOverlay declaration. Below is the code that I am using in my app:



public class ChildModeActivity extends BaseActivity {
private CameraSource cameraSource = null;
private CameraSourcePreview preview;
private GraphicOverlay graphicOverlay;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_child_mode);
preview = (CameraSourcePreview) findViewById(R.id.childCameraPreview);
if (preview == null) {
Log.d("TAG_FACE", "Preview is null");
}
graphicOverlay = (GraphicOverlay) findViewById(R.id.childFaceOverlay);
if (graphicOverlay == null) {
Log.d("TAG_FACE", "graphicOverlay is null");
}
if (allPermissionsGranted()) {
createCameraSource();
} else {
getRuntimePermissions();
}
}
private void startCameraSource() {
if (cameraSource != null) {
try {
if (preview == null) {
Log.d("TAG_FACE", "resume: Preview is null");
}
if (graphicOverlay == null) {
Log.d("TAG_FACE", "resume: graphOverlay is null");
}
preview.start(cameraSource, graphicOverlay);
} catch (IOException e) {
Log.e("TAG_FACE", "Unable to start camera source.", e);
cameraSource.release();
cameraSource = null;
}
}
}

private void createCameraSource() {
try {
// If there's no existing cameraSource, create one.
if (cameraSource == null) {
Log.i("TAG_FACE", "Camera Source is Null so create new one");
cameraSource = new CameraSource(this, graphicOverlay);
cameraSource.setFacing(CameraSource.CAMERA_FACING_FRONT);
// cameraSource = new CameraSource(this);
cameraSource.setMachineLearningFrameProcessor(new FaceDetectionProcessor());
}
}catch (Exception e){
Log.i("TAG_FACE" , " Create Camera Source Exception:" + e.getMessage());
}
}


In the above code my BaseActivity extends AppCompatActivity.



Whenever I run the app, I am getting that "Preview is null" and "graphicOverlay is null" in the log. The preview is not showing.










share|improve this question
















I have implemented the Firebase ML Kit for face-detection in my app. In the demo app, where I created a new Firebase project and added the google json file its working fine. But in the existing app (the one on the playstore app) it returns null for the CameraSourcePreview and graphicOverlay declaration. Below is the code that I am using in my app:



public class ChildModeActivity extends BaseActivity {
private CameraSource cameraSource = null;
private CameraSourcePreview preview;
private GraphicOverlay graphicOverlay;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_child_mode);
preview = (CameraSourcePreview) findViewById(R.id.childCameraPreview);
if (preview == null) {
Log.d("TAG_FACE", "Preview is null");
}
graphicOverlay = (GraphicOverlay) findViewById(R.id.childFaceOverlay);
if (graphicOverlay == null) {
Log.d("TAG_FACE", "graphicOverlay is null");
}
if (allPermissionsGranted()) {
createCameraSource();
} else {
getRuntimePermissions();
}
}
private void startCameraSource() {
if (cameraSource != null) {
try {
if (preview == null) {
Log.d("TAG_FACE", "resume: Preview is null");
}
if (graphicOverlay == null) {
Log.d("TAG_FACE", "resume: graphOverlay is null");
}
preview.start(cameraSource, graphicOverlay);
} catch (IOException e) {
Log.e("TAG_FACE", "Unable to start camera source.", e);
cameraSource.release();
cameraSource = null;
}
}
}

private void createCameraSource() {
try {
// If there's no existing cameraSource, create one.
if (cameraSource == null) {
Log.i("TAG_FACE", "Camera Source is Null so create new one");
cameraSource = new CameraSource(this, graphicOverlay);
cameraSource.setFacing(CameraSource.CAMERA_FACING_FRONT);
// cameraSource = new CameraSource(this);
cameraSource.setMachineLearningFrameProcessor(new FaceDetectionProcessor());
}
}catch (Exception e){
Log.i("TAG_FACE" , " Create Camera Source Exception:" + e.getMessage());
}
}


In the above code my BaseActivity extends AppCompatActivity.



Whenever I run the app, I am getting that "Preview is null" and "graphicOverlay is null" in the log. The preview is not showing.







android firebase firebase-mlkit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 16:36









Ali Khaki

8081520




8081520










asked Nov 22 '18 at 13:04









NathiyaNathiya

1088




1088













  • Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

    – Nathiya
    Dec 8 '18 at 12:57











  • I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

    – Nathiya
    Dec 8 '18 at 12:59



















  • Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

    – Nathiya
    Dec 8 '18 at 12:57











  • I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

    – Nathiya
    Dec 8 '18 at 12:59

















Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

– Nathiya
Dec 8 '18 at 12:57





Camera preview is null received because of multiple view issue. After added the Camerapreview in multiple layout views issue is fixed. Sorry, it was a stupid mistake done by me.

– Nathiya
Dec 8 '18 at 12:57













I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

– Nathiya
Dec 8 '18 at 12:59





I have raised the another question reg ML Kit Face Detection. I have to run Face detection using ML kit in background service class. pls have a look stackoverflow.com/questions/53682721/…

– Nathiya
Dec 8 '18 at 12:59












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431681%2fml-kit-facedetection-camerasourcepreview-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431681%2fml-kit-facedetection-camerasourcepreview-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?