我创建并运行在Eclipse中使用AVD基本的Android MyFirstAppIllegalStateException异常在基本MyFirstApp
http://developer.android.com/training/basics/firstapp/starting-activity.html
,我得到以下错误:
"java.lang.IllegalStateException:
找不到方法sendMesaage (查看)中activity
类com.example.myfirstapp.MainActivity
onClick处理程序view
类android.widget.Button"
该方法存在d的的onClick元素存在:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMesaage"/>
方法调用:
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMesaageActivity.class);
EditText edit_message= (EditText) findViewById(R.id.edit_message);
String message = edit_message.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
“sendMesaage”不是“sendMessage”吗?如果这不是问题,我们还需要查看您的代码。 – 2012-08-03 14:33:45
也许你拼写错误的消息?发布主要活动代码... – javajavajava 2012-08-03 14:35:00
这很明显是一个拼写错误。错误代码确切地说出了什么问题。 – 2012-08-03 14:59:02