1
I have a problem with Intent, something that was supposed to be simple is causing me problems...
I’m trying to create a second button for call another screen, but as soon as I add the following code the application to:
mAnaliseButton = (Button) findViewById(R.id.custom_view_analiseDetalhada);
mAnaliseButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Books.this, AnaliseScreen.class);
startActivity(i);
finish();
}
});
There are (4) screens created in my application which are respectively:
- Activitysplashscreen
- Aboutscreen
- Books
Analisescreen
The Books.class screen is where the user’s camera opens.
To Activitysplashscreen starts, automatically calling the Aboutscreen. In the Aboutscreen there is a button to call the Books and in the Books once it detects the Imagetarget opens a Bookie with the dice and a button to call the Analisescreen.
But in case I add the code above, as soon as I click the Button on the screen Aboutscreen to start the Books the Application stops working, the interesting thing is that there is already a button inside Books and it works perfectly and does not give this type of error.
Follow the codes below(If necessary, I will send you the ones you ask for): NOTE: I WILL POST THE CODES THROUGH A LINK, AS THEY ARE PASSING THE MAXIMUM LIMIT OF CHARACTERS OF THE FORUM.
- Books java. https://paste.ofcode.org/c8TsPaY4bVx99c6yGCrtF
- Aboutscreen.java https://paste.ofcode.org/HJX4v6hfvifyXXNkD7jxe2
- Analisescreen.java https://paste.ofcode.org/jRww8Sfak6XrhQLciVd67x
about_screen.xml
parse_screen.xml
book_data_layout.xml
camera_overlay_books.xml
Androidmanifest.xml
** ERROR **:
05-29 16:23:38.002 21258-21258/com.vuforia.samples.Books E/Androidruntime: FATAL EXCEPTION: main Process: com.vuforia.samples.Books, PID: 21258 java.lang.Runtimeexception: Unable to start Activity Componentinfo{com.vuforia.samples.Books/com.vuforia.samples.Books.app.Books.Books}: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$Onclicklistener)' on a null Object Reference at android.app.Activitythread.performLaunchActivity(Activitythread.java:2584) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2650) at android.app.Activitythread. -wrap11(Activitythread.java) at android.app.Activitythread$H.handleMessage(Activitythread.java:1505) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.Activitythread.main(Activitythread.java:5776) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:888) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:749) Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$Onclicklistener)' on a null Object Reference at com.vuforia.samples.Books.app.Books.Books.startLoadingAnimation(Books.java:523) at com.vuforia.samples.Books.app.Books.Books.onCreate(Books.java:343) at android.app.Activity.performCreate(Activity.java:6270) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2537) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2650) at android.app.Activitythread. -wrap11(Activitythread.java) at android.app.Activitythread$H.handleMessage(Activitythread.java:1505) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.Activitythread.main(Activitythread.java:5776) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:888) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:749)
What error does it make? There is Activity Books declared on Androidmanifest.xml?
– ramaral
@ramaral , I forgot to post the Androidmanifest. I just posted there on the question, give a look there for kindness.
– Thiago Saad
You can see why this log error is occurring.
– Reginaldo Rigo
I have the impression that the Finish() after the startActivity(i) closes Activity mother. Tries to comment.
– Edson Santos
@Reginaldorigo , I put the error in my publication.
– Thiago Saad
@Edsonfsantos , I tried to remove Finish(); from the two button and after a button only the same thing happened.
– Thiago Saad
And when you click on the first red line of the error. Where it takes you in the sources?
– Reginaldo Rigo