当我将数据从一个活动发送到另一个活动时,我正处于异常之下。 可能这是一个愚蠢的问题。但我是Android新手
03-22 21:35:59.164: E/AndroidRuntime(17721): FATAL EXCEPTION: main
03-22 21:35:59.164: E/AndroidRuntime(17721): java.lang.IllegalStateException: Could not execute method of the activity
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.view.View$1.onClick(View.java:2144)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.view.View.performClick(View.java:2485)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.view.View$PerformClick.run(View.java:9080)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.os.Handler.handleCallback(Handler.java:587)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.os.Looper.loop(Looper.java:130)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-22 21:35:59.164: E/AndroidRuntime(17721): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 21:35:59.164: E/AndroidRuntime(17721): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 21:35:59.164: E/AndroidRuntime(17721): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-22 21:35:59.164: E/AndroidRuntime(17721): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-22 21:35:59.164: E/AndroidRuntime(17721): at dalvik.system.NativeStart.main(Native Method)
03-22 21:35:59.164: E/AndroidRuntime(17721): Caused by: java.lang.reflect.InvocationTargetException
03-22 21:35:59.164: E/AndroidRuntime(17721): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 21:35:59.164: E/AndroidRuntime(17721): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 21:35:59.164: E/AndroidRuntime(17721): at android.view.View$1.onClick(View.java:2139)
03-22 21:35:59.164: E/AndroidRuntime(17721): ... 11 more
03-22 21:35:59.164: E/AndroidRuntime(17721): Caused by: java.lang.NullPointerException
03-22 21:35:59.164: E/AndroidRuntime(17721): at kc.krishna.messagesending.Message.messgaeSend(Message.java:36)
03-22 21:35:59.164: E/AndroidRuntime(17721): ... 14 more
Message.java
ublic class Message extends Activity {
TextView sending;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
sending = (TextView) findViewById(R.id.editText1);
}
public void messgaeSend(View v)
{
Intent sendIntent = null;
String sendText = sending.getText().toString();
Toast.makeText(getApplicationContext(), sendText, Toast.LENGTH_SHORT).show();
sendIntent.putExtra("SEND_MESSAGE", sendText);
sendIntent = new Intent(Message.this,Receive.class);
startActivity(sendIntent);
}
}
我在下面的行获得了Exception。
sendIntent.putExtra("SEND_MESSAGE", sendText);
请帮我解决这个问题。
答案 0 :(得分:1)
sendIntent
为null
,您正在尝试调用方法putExtra
。在调用Intent构造函数后移动sendIntent.putExtra
:
sendIntent = new Intent(Message.this,Receive.class);
sendIntent.putExtra("SEND_MESSAGE", sendText);
startActivity(sendIntent);