我有一个活动,可以说活动 A。
public class ActivityA extends Activity{
static int id_original;
.
.
.
id_original = R.drawable.afra_o;
}
afra_o 是另一个活动布局的 ImageView。假设活动 B。在活动 A 中,我想将 id_original 设置为某个可绘制对象,然后我想通过在活动 B 中引用 id_original 来更改 B 的 ImageView。
public class ActivityB extends Activity {
ImageView view_correct = (ImageView)findViewById(R.id.image_original);
view_correct.setImageResource(ActivityA.id_original);
setContentView(R.layout.activity_B);
像这个。但是我遇到了这样的错误
03-06 11:57:55.845: E/AndroidRuntime(10791): FATAL EXCEPTION: main
03-06 11:57:55.845: E/AndroidRuntime(10791): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.turkishlogoquiz/com.example.turkishlogoquiz.CorrectActivity}: java.lang.NullPointerException
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.os.Looper.loop(Looper.java:137)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-06 11:57:55.845: E/AndroidRuntime(10791): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 11:57:55.845: E/AndroidRuntime(10791): at java.lang.reflect.Method.invoke(Method.java:511)
03-06 11:57:55.845: E/AndroidRuntime(10791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
03-06 11:57:55.845: E/AndroidRuntime(10791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
03-06 11:57:55.845: E/AndroidRuntime(10791): at dalvik.system.NativeStart.main(Native Method)
03-06 11:57:55.845: E/AndroidRuntime(10791): Caused by: java.lang.NullPointerException
03-06 11:57:55.845: E/AndroidRuntime(10791): at com.example.turkishlogoquiz.CorrectActivity.onCreate(CorrectActivity.java:20)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.Activity.performCreate(Activity.java:5206)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-06 11:57:55.845: E/AndroidRuntime(10791): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
任何帮助,请。