Android 2.3.3崩溃 - ImageView

时间:2013-12-31 04:01:09

标签: android memory crash imageview android-2.3-gingerbread

我试图使用的图像仅为5.6kb 我使用以下代码:

的setContentView(R.layout.activity_main);

...

ImageView byreference =(ImageView)findViewById(R.id.byreference);

<ImageView
    android:id="@+id/byreference"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/byreference" />

我收到以下错误:

12-31 03:50:30.835: E/AndroidRuntime(437): FATAL EXCEPTION: main
12-31 03:50:30.835: E/AndroidRuntime(437): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.turbo/com.example.turbo.MainActivity}: java.lang.NullPointerException
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.os.Looper.loop(Looper.java:123)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-31 03:50:30.835: E/AndroidRuntime(437):  at java.lang.reflect.Method.invokeNative(Native Method)
12-31 03:50:30.835: E/AndroidRuntime(437):  at java.lang.reflect.Method.invoke(Method.java:507)
12-31 03:50:30.835: E/AndroidRuntime(437):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-31 03:50:30.835: E/AndroidRuntime(437):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-31 03:50:30.835: E/AndroidRuntime(437):  at dalvik.system.NativeStart.main(Native Method)
12-31 03:50:30.835: E/AndroidRuntime(437): Caused by: java.lang.NullPointerException
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.Activity.findViewById(Activity.java:1647)
12-31 03:50:30.835: E/AndroidRuntime(437):  at com.example.turboverse.MainActivity.<init>(MainActivity.java:18)
12-31 03:50:30.835: E/AndroidRuntime(437):  at java.lang.Class.newInstanceImpl(Native Method)
12-31 03:50:30.835: E/AndroidRuntime(437):  at java.lang.Class.newInstance(Class.java:1409)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-31 03:50:30.835: E/AndroidRuntime(437):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
12-31 03:50:30.835: E/AndroidRuntime(437):  ... 11 more

0 个答案:

没有答案