mohammad aljammali
mohammad aljammali

Reputation: 51

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

Upvotes: 1

Views: 6797

Answers (2)

MINGdev
MINGdev

Reputation: 11

Create this method in your target fragment:

public static CartFragment newInstance() {
    return new CartFragment();
}

Upvotes: 1

OneCricketeer
OneCricketeer

Reputation: 191738

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.

Upvotes: 0

Related Questions