这是我正在使用的代码:
progressFrame = (FrameLayout) findViewById(R.id.progressFrame);
progressFrame.setBackgroundResource(R.drawable.startprogress);
在 Android 2.3.3 上一切正常,但在 Android 4 上,它在尝试运行“setBackgroundResource”行时崩溃。这是 logcat 消息:
07-06 17:31:28.159: W/dalvikvm(11848): threadid=1: thread exiting with uncaught exception (group=0x40be81f8)
07-06 17:31:28.167: E/AndroidRuntime(11848): FATAL EXCEPTION: main
07-06 17:31:28.167: E/AndroidRuntime(11848): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bosi.sweetsmell/com.bosi.sweetsmell.activity.RubActivity}: java.lang.NullPointerException
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.os.Looper.loop(Looper.java:137)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread.main(ActivityThread.java:4514)
07-06 17:31:28.167: E/AndroidRuntime(11848): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 17:31:28.167: E/AndroidRuntime(11848): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 17:31:28.167: E/AndroidRuntime(11848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-06 17:31:28.167: E/AndroidRuntime(11848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-06 17:31:28.167: E/AndroidRuntime(11848): at dalvik.system.NativeStart.main(Native Method)
07-06 17:31:28.167: E/AndroidRuntime(11848): Caused by: java.lang.NullPointerException
07-06 17:31:28.167: E/AndroidRuntime(11848): at com.bosi.sweetsmell.activity.RubActivity.onCreate(RubActivity.java:35)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.Activity.performCreate(Activity.java:4465)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
07-06 17:31:28.167: E/AndroidRuntime(11848): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
07-06 17:31:28.167: E/AndroidRuntime(11848): ... 11 more
在此希望有人可以提供帮助!