我有两个活动第一个有两个按钮第二个有一个文本视图
我需要的是当我单击第一个按钮时,第二个活动打开并且 textview 显示(你好)当我单击第二个按钮时,第二个活动打开并且 textview 显示(你好吗)
这是第一个活动布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:scrollbars="none"
tools:context=".DailyPrayersActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/btn1"
style="@style/Button_Normal"
android:background="@drawable/btn01"
android:onClick="hello"
android:text="@string/hello" />
<Button
android:id="@+id/btn2"
style="@style/Button_Normal"
android:background="@drawable/btn01"
android:onClick="hru"
android:text="@string/hru" />
</LinearLayout>
</ScrollView>
这是第一个活动的java类
package com.daily.morning;
public class FirstActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_1);
}
public void hello(View v) {
Intent i1 = new Intent(firstActivity.this, SecondActivity.class);
SecondActivity.textview.setText("Hello");
startActivity(i1);
finish();
}
public void hru(View v) {
Intent i2 = new Intent(FirstActivity.this, SecondActivity.class);
SecondActivity.textview.setText("good morning");
startActivity(i2);
finish();
}
}
当我单击第一个按钮或第二个按钮时,应用程序强制关闭
这是日志猫
>>09-06 14:26:24.054: E/AndroidRuntime(30993): FATAL EXCEPTION: main
09-06 14:26:24.054: E/AndroidRuntime(30993): java.lang.IllegalStateException: Could not execute method of the activity
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$1.onClick(View.java:3699)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View.performClick(View.java:4223)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$PerformClick.run(View.java:17275)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Handler.handleCallback(Handler.java:615)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Handler.dispatchMessage(Handler.java:92)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Looper.loop(Looper.java:137)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 14:26:24.054: E/AndroidRuntime(30993): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
09-06 14:26:24.054: E/AndroidRuntime(30993): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
09-06 14:26:24.054: E/AndroidRuntime(30993): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103)
09-06 14:26:24.054: E/AndroidRuntime(30993): at dalvik.system.NativeStart.main(Native Method)
09-06 14:26:24.054: E/AndroidRuntime(30993): Caused by: java.lang.reflect.InvocationTargetException
09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$1.onClick(View.java:3694)
09-06 14:26:24.054: E/AndroidRuntime(30993): ... 12 more
09-06 14:26:24.054: E/AndroidRuntime(30993): Caused by: java.lang.NullPointerException
09-06 14:26:24.054: E/AndroidRuntime(30993): at com.daily.morning.FirstActivity.hello(FirstActivity.java:38)
09-06 14:26:24.054: E/AndroidRuntime(30993): ... 15 more