IllegalStateException: Could not find method insert(View) in a parent or ancestor Context class android.support.v7.widget.AppCompatButton

后端 未结 2 1309
感情败类
感情败类 2020-12-11 21:50

I have launched the program in single project which work properly.

However, when I have copied and pasted into a bigger project, it gives me bellow error in logcat.

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 22:15

    I found the error.

    In layout second_layout.xml, you defined Button with android:onClick="insert"

    This layout is included in activity_user_profile.xml

    This activity_user_profile.xml is used in Main2Activity.java

    So, that is the issue:

    "Insert Button" is being used in Main2Activity.java. However, that class does not have any method public void insert(View view)

    So, add this to your Main2Activity.java:

    public void insert(View view){
        // Add the code that you want
        // Or do nothing if you want
    }
    

    Rememeber

    If you set any onClick event in a layout file (xml), you have to create the method in the parent activity that will use that layout.

提交回复
热议问题