Getting IllegalStateException on button click

后端 未结 4 1124
梦谈多话
梦谈多话 2020-12-04 01:51

On clicking a button to migrate to another activity, the app crashes and log shows:

java.lang.IllegalStateException: Could not execute method for android:onC         


        
相关标签:
4条回答
  • 2020-12-04 02:12

    The key part of the full stack trace is found here:

    Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.unholyalliance.infinitestream/com.example.unholyalliance.infinitestream.Host}; have you declared this activity in your AndroidManifest.xml

    It appears you do not have this Host activity declared in your manifest file. Open AndroidManifest.xml and check for or add the following:

    <activity
        android:name=".Host" />
    

    Also make sure you fix the issue in Host to first only declare your TextView and then assign the value in onCreate() after setContentView().

    private TextView service_status;
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_host);
        service_status = (TextView) findViewById(R.id.textView1);
        ...
    }
    
    0 讨论(0)
  • 2020-12-04 02:16

    Check your Parcelable objects or Serializable objects that are putted intent whether is correct. Inspect carefully subclasses and add essential interfaces (Serializable or Parcelable) if you need.

    0 讨论(0)
  • 2020-12-04 02:33

    Above answers are correct, but also double check to register your class in Manifest.

     <activity android:name=".Downloaded"
    
                android:label="@string/app_name">
    
            </activity>
    

    .Downloaded is your class name above.

    0 讨论(0)
  • 2020-12-04 02:36

    Make sure that your onClick in Button view in activity_main.xml is like this android:onClick="host"

    Example:

    <Button
        android:id="@+id/main_activity_bt_host"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/host"
        android:onClick="host" />
    
    0 讨论(0)
提交回复
热议问题