当我在现有版本上安装apk时,我的应用程序抛出异常。
以下是重现错误的步骤:
这是一个例外:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.empystudio.cashflow/com.empystudio.cashflow.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.empystudio.cashflow.MainActivity.onCreate(MainActivity.java:66)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
... 11 more
这是MainActivity的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
documentsView = (ImageView) findViewById(R.id.documents_view);
backupView = (ImageView) findViewById(R.id.backup_view);
restoreView = (ImageView) findViewById(R.id.restore_view);
helpView = (ImageView) findViewById(R.id.help_view);
versionView = (TextView) findViewById(R.id.ver_name);
...
行号66是
documentsView = (ImageView) findViewById(R.id.documents_view);
我试图评论我应用程序的很多部分但没有成功,现在我不知道如何解决这个问题。
[编辑]
更多信息:
[编辑]
activity_main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/adLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<ImageView
android:id="@+id/documents_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="false"
android:contentDescription="@string/title_activity_documents"
android:gravity="center"
android:src="@drawable/menu_documents" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/title_activity_documents" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<ImageView
android:id="@+id/help_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/menu_help"
android:gravity="center"
android:src="@drawable/menu_help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/menu_help" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<ImageView
android:id="@+id/backup_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/menu_backup_database"
android:gravity="center"
android:src="@drawable/menu_backup" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/menu_backup_database" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
tools:ignore="UseCompoundDrawables" >
<ImageView
android:id="@+id/restore_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/menu_restore_database"
android:gravity="center"
android:src="@drawable/menu_restore" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/menu_restore_database" />
</LinearLayout>
</TableRow>
</TableLayout>
<TextView
android:id="@+id/ver_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:gravity="right"
android:textAppearance="?android:attr/textAppearanceSmall" />
[编辑]
这里有两个不同的APK来重现错误:
http://www.empystudio.com/downloads/private/cashflow_1.0.64.apk
http://www.empystudio.com/downloads/private/cashflow_1.0.65.apk
重现错误: