下面的代码中没有错误,第一个活动效果很好,但是在单击按钮时它会停止(崩溃)
帮帮我
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et = (EditText) findViewById(R.id.textView1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent =new Intent(MainActivity.this, Second.class);
intent.putExtra("thetv",et.getText().toString() );
startActivity(intent);
}
});
}
}
public class Second extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second) ;
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("thetv"));
}
}
日志数据
05-19 21:51:06.089: W/KeyCharacterMap(1561): id 0 没有键盘
05-19 21:51:06.089:W/KeyCharacterMap(1561):使用默认键盘映射:/system/usr/keychars/qwerty.kcm.bin
05-19 21:51:15.659: D/AndroidRuntime(1561): 关闭虚拟机
05-19 21:51:15.659: W/dalvikvm(1561): threadid=1: 线程退出未捕获异常 (group=0x40015560)
05-19 21:51:15.669:E/AndroidRuntime(1561):致命异常:主要
05-19 21:51:15.669: E/AndroidRuntime(1561): java.lang.NullPointerException
05-19 21:51:15.669: E/AndroidRuntime(1561): at com.nav.activitieslearn.MainActivity$1.onClick(MainActivity.java:26)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.view.View.performClick(View.java:2485)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.view.View$PerformClick.run(View.java:9080)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.os.Handler.handleCallback(Handler.java:587)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.os.Handler.dispatchMessage(Handler.java:92)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.os.Looper.loop(Looper.java:123)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 android.app.ActivityThread.main(ActivityThread.java:3683)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 java.lang.reflect.Method.invokeNative(Native Method)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 java.lang.reflect.Method.invoke(Method.java:507)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-19 21:51:15.669: E/AndroidRuntime(1561): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-19 21:51:15.669: E/AndroidRuntime(1561): at dalvik.system.NativeStart.main(Native Method)
05-19 21:51:19.538: I/Process(1561): 发送信号。PID:1561 SIG:9
安卓清单
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.nav.activitieslearn.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.nav.activitieslearn.Second" >
</activity>
</application>