mohammad aljammali mohammad aljammali - 4 months ago 40
Android Question

cannot resolve method newinstance()

I am trying to understand how to use Api.camera2
and I am following google sample from this link
https://github.com/googlesamples/android-Camera2Basic

when I open the project it works but when I try it to rebuild the app to see the effect of each part of the code I got the following error
cannotresolve method newinstance()
it is the main java class



package com.example.jimy.camera_app_learn;




import android.app.Activity;
import android.os.Bundle;

public class CameraActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
if (null == savedInstanceState) {
getFragmentManager().beginTransaction()
.replace(R.id.container, Camera2BasicFragment.newInstance())
.commit();
}
}

}





i tried exporting project setting from the original project but it did not work

Answer

Did you copy the code from the Github repo you linked to?

This line has the newInstance() method, yet your error clearly says it cannot be found, so you should either implement it or just completely copy the code from that repository.

Comments