我有一个包含字符串、方法等的活动。我想使用另一个活动来阅读它。这是我的代码。
Activitymain.java
public class Activitymain extends Activity{
public String input;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_main);
input = "This is the input";
}
另一个活动。
第二幕.java
public class SecondAct extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secon_act);
Activitymain am = (Activitymain) this;
Toast.maketext(this, ""+am.input,Toast.LENGTH_LONG).show();
}
但是当我去另一个活动时它崩溃了。这是日志:
11-14 14:42:45.000: E/AndroidRuntime(16457): FATAL EXCEPTION: main
11-14 14:42:45.000: E/AndroidRuntime(16457): java.lang.NullPointerException
11-14 14:42:45.000: E/AndroidRuntime(16457): at com.example.tabs.SecondAct.Start_Call(SecondAct.java:384)
11-14 14:42:45.000: E/AndroidRuntime(16457): at com.example.tabs.SecondAct$1.onClick(SecondAct.java:420)
11-14 14:42:45.000: E/AndroidRuntime(16457): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:946)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.widget.AbsListView.performItemClick(AbsListView.java:1114)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2933)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.widget.AbsListView$1.run(AbsListView.java:3691)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.os.Handler.handleCallback(Handler.java:615)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.os.Looper.loop(Looper.java:153)
11-14 14:42:45.000: E/AndroidRuntime(16457): at android.app.ActivityThread.main(ActivityThread.java:5086)
11-14 14:42:45.000: E/AndroidRuntime(16457): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 14:42:45.000: E/AndroidRuntime(16457): at java.lang.reflect.Method.invoke(Method.java:511)
11-14 14:42:45.000: E/AndroidRuntime(16457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
11-14 14:42:45.000: E/AndroidRuntime(16457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
11-14 14:42:45.000: E/AndroidRuntime(16457): at dalvik.system.NativeStart.main(Native Method)