1

该应用程序运行良好,但是当我销毁应用程序时出现问题。这是我的错误日志。

04-04 12:32:40.529: E/AndroidRuntime(6290): FATAL EXCEPTION: main
04-04 12:32:40.529: E/AndroidRuntime(6290): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3955)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.ActivityThread.access$1300(ActivityThread.java:127)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.os.Looper.loop(Looper.java:137)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.ActivityThread.main(ActivityThread.java:4441)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at java.lang.reflect.Method.invokeNative(Native Method)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at java.lang.reflect.Method.invoke(Method.java:511)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at dalvik.system.NativeStart.main(Native Method)
04-04 12:32:40.529: E/AndroidRuntime(6290): Caused by: java.lang.NullPointerException
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
04-04 12:32:40.529: E/AndroidRuntime(6290):     at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
04-04 12:32:40.529: E/AndroidRuntime(6290):     ... 11 more

我找到了导致它的视图,但我不明白为什么以及将来如何避免它。

这是我在布局文件中的视图并在代码中对其进行初始化:

<LinearLayout
                android:id="@+id/terms_button_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/dp10"
                android:background="@drawable/car_component_border"
                android:padding="@dimen/cell_padding_top" >

                <ImageView
                    android:id="@+id/terms_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/terms" />

                <TextView
                    android:id="@+id/terms_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/terms_of_use"
                    android:textAppearance="?android:attr/textAppearanceLarge" />
            </LinearLayout>


terms = (LinearLayout) findViewById(R.id.terms_button_layout);

我究竟做错了什么?

4

0 回答 0