0

I'm quite new at Android studio, so I'm sure I'm just missing something simple. The strange thing is that this app has 3 activities, the first 2 I can switch between with no problems, but the third crashes out. I have narrowed the code down as much as I can, but I can't even swap to a completely blank xml page.

Code of swap button:

public void goA3(View V) {
    Intent intent = new Intent(this, ThirdActivity.class);
    startActivity(intent);
}

Code of ThirdActivity.class:

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ThirdActivity extends AppCompatActivity {

//  static final public String PREF_STRING_3 = "string_3";


AppInfo appInfo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_third);
    appInfo = AppInfo.getInstance(this);
}
}

Basic XML for blank page:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

</LinearLayout>

Thanks, again, I'm sure its something basic I'm missing.

Logcat:

FATAL EXCEPTION: main
                                                                                    Process: com.dealfaro.luca.backandforthstudio, PID: 2586
                                                                                    java.lang.IllegalStateException: Could not execute method for android:onClick
                                                                                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
                                                                                        at android.view.View.performClick(View.java:5637)
                                                                                        at android.view.View$PerformClick.run(View.java:22429)
                                                                                        at android.os.Handler.handleCallback(Handler.java:751)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                                     Caused by: java.lang.reflect.InvocationTargetException
                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
                                                                                        at android.view.View.performClick(View.java:5637) 
                                                                                        at android.view.View$PerformClick.run(View.java:22429) 
                                                                                        at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
                                                                                     Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.dealfaro.luca.backandforthstudio/com.dealfaro.luca.backandforthstudio.ThirdActivity}; have you declared this activity in your AndroidManifest.xml?
                                                                                        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
                                                                                        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
                                                                                        at android.app.Activity.startActivityForResult(Activity.java:4225)
                                                                                        at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                                        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
                                                                                        at android.app.Activity.startActivity(Activity.java:4522)
                                                                                        at android.app.Activity.startActivity(Activity.java:4490)
                                                                                        at com.dealfaro.luca.backandforthstudio.MainActivity.goA3(MainActivity.java:67)
                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                        at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) 
                                                                                        at android.view.View.performClick(View.java:5637) 
                                                                                        at android.view.View$PerformClick.run(View.java:22429) 
                                                                                        at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Luke
  • 483
  • 2
  • 6
  • 13
  • 2
    Check your logcat for the [stack trace](http://stackoverflow.com/questions/23353173) from the crash. – Mike M. Apr 25 '17 at 23:20
  • Posted, from what I can tell it doesn't like the buttonclick. However, when I mapped the same button to try and move from the main page to the second activity (instead of the third) it worked, so I'm not sure the problem is with the button. Thanks for the link. – Luke Apr 25 '17 at 23:34
  • 1
    `Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {...ThirdActivity}; have you declared this activity in your AndroidManifest.xml?` - Have you? – Mike M. Apr 25 '17 at 23:37
  • You should carefully read the entire stack trace. As Mike M posted above, it tells you exactly how to fix the problem. If you do not understand that part of the message, google it for more tips. – Code-Apprentice Apr 25 '17 at 23:40

2 Answers2

2

You need to add your third activity to your manifest.

<activity android:name="com.yourpackage.ThirdActivity"/>
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
0

add your activity in Android Manifest file and it will surely works