My application throws an exception when I install the apk on an existing version.
These are the steps to reproduce my error:
- Install application (i.e. v1) and run it (no error found)
- Install the same apk or a new one (i.e. v2) with a minor update
- A NullReferenceException is thrown
- Install the same apk of #2
- Everything works fine
This is the exception:
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
This is the code of 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);
...
Line no. 66 is
documentsView = (ImageView) findViewById(R.id.documents_view);
I tried to comment so many part of my application without success and now I have no idea on how to solve this problem.
[Edit]
Some more info:
- MainActivity is the launcher Activity in the Android manifest
- I can't catch the exception (the only stack that I have the one from the Google Play Exception management)
- If I comment line 66 I still have an exception
[Edit]
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" />
[Edit]
Here there are two different APK to reproduce the error:
http://www.empystudio.com/downloads/private/cashflow_1.0.64.apk
http://www.empystudio.com/downloads/private/cashflow_1.0.65.apk
To reproduce the error:
- Install ver. 64
- Open it
- Install ver. 65
- Open it (here I receive an error)
- Install ver. 65 again
- Everything works fine