0

I made the fatal mistake of upgrading to AS 3.1 from 3.0.1 I have written a simple app that on MainActivity a button has a onClick = onNEXT when clicked uses an Intent to navigate to ListActivity the XML is bare bones I am using API 26 min and max this line of code in Build Gradle project looks wrong ? classpath 'com.android.tools.build:gradle:3.1.0'

here is the error 03-31 04:26:14.306 7133-7133/com.androidstackoverflow.atestcon E/AndroidRuntime: FATAL EXCEPTION: main Process: com.androidstackoverflow.atestcon, PID: 7133 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidstackoverflow.atestcon/android.app.ListActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1932) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615) at android.app.Activity.startActivityForResult(Activity.java:4472) at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67) at android.app.Activity.startActivityForResult(Activity.java:4430) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720) at android.app.Activity.startActivity(Activity.java:4791) at android.app.Activity.startActivity(Activity.java:4759) at com.androidstackoverflow.atestcon.MainActivity.onNEXT(MainActivity.java:21) at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:6256) at android.view.View$PerformClick.run(View.java:24701) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

My Manifest is clean

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ListActivity">

    </activity>
</application>

here is the MainActivity code

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button btnNext = findViewById(R.id.btnNext);
}

public void onNEXT(View view){
    Intent intent = new Intent(MainActivity.this, ListActivity.class);
    startActivity(intent);
}

}

I have never been more disappointed every time I update AS it is one mess after another I have uninstalled and reinstalled 3 times and would appreciate any help with this The Emulator when it is configured does not let you set fields the way it did in AS 3.0.1 OLDER projects are not working they have this error in the Styles folder

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

The word Theme is in RED

James_Duh
  • 1,321
  • 11
  • 31

2 Answers2

1

Check the imports at beginning of MainActivity..By mistake you have imported android.app.ListActivity. import yourpackagename.ListActivity

Intent intent = new Intent(MainActivity.this, ListActivity.class); startActivity(intent);

Mihir Joshi
  • 117
  • 4
  • I have post the error after removing the ListActivity from the Imports Could you please look at the Manifest code – James_Duh Mar 31 '18 at 18:59
  • Can u please post ur xml file where u declared onclick? – Mihir Joshi Mar 31 '18 at 19:03
  • May be u have forgot to do findviewbyid in some view..please check it – Mihir Joshi Mar 31 '18 at 19:07
  • I posted the code and triple checked the findbyid it is all correct Thanks – James_Duh Mar 31 '18 at 19:10
  • Hey just change the name of activity..for example ..ListActivity to MyListActivity.. It will solve ur issue.. Bingo! – Mihir Joshi Mar 31 '18 at 19:12
  • just for fun I tested the wrong password and the code executes fine Will try your suggestion – James_Duh Mar 31 '18 at 19:23
  • Why Why did we need to change the name of the ListActivity One Thought I have two apps one is PWKeeper the other is NewKeeper code is the same I am using NewKeeper to migrate code to a tutorial for web page "androidstackoverflow.com" – James_Duh Mar 31 '18 at 19:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/167952/discussion-between-mihir-joshi-and-james-duh). – Mihir Joshi Mar 31 '18 at 19:31
0

Your activity's name is ListActivity but there is also an android.app.ListActivity. Android thought you mean the later one.
So you can just change new Intent(MainActivity.this, ListActivity.class); to new Intent(MainActivity.this, com.androidstackoverflow.atestcon.ListActivity.class);
Or change a name for your ListActivity.

Meow Cat 2012
  • 928
  • 1
  • 9
  • 21
  • Cat I have post the error after removing the ListActivity from the Imports Could you please look at the Manifest code – James_Duh Mar 31 '18 at 18:58