The application crashes when launched from the phone, but works fine when launched from the computer

After 3 days, I was able to run the old application on my device! But only when the command comes from my computer ...

I will explain. When I run the application from Android Studio on my phone, it starts up fine, and that's great. But when I run it directly from my phone, I get to Catlog that String is NULL. I do not understand what might cause this. It works great when the application starts from my computer, but not from the phone ...

Please, help!

Edit 1 : add actions to AndroidManifest.xml

<activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name=".ManageAccountActivity"/> <activity android:name=".RegionListActivity"/> <activity android:name=".ClubListActivity"/> <activity android:name=".SearchActivity"/> <activity android:name=".TeetimesListActivity"/> <activity android:name=".ConfirmationActivity"/> <activity android:name=".TermsAndConditionsActivity"/> <activity android:name=".TabletSearchActivity"/> <activity android:name=".TabletConfirmationActivity"/> <activity android:name=".PreferencesActivity"/> 

Edit 2 : error log

 01-08 16:08:47.194 26704-26704/ca.gggolf.aminutegolf E/ACRA: ACRA caught a RuntimeException for ca.gggolf.aminutegolf java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.gggolf.aminutegolf/ca.gggolf.aminutegolf.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) at android.app.ActivityThread.access$800(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String[] java.lang.String.split(java.lang.String)' on a null object reference at ca.gggolf.aminutegolf.LoginActivity.checkForNewBooking(LoginActivity.java:676) at ca.gggolf.aminutegolf.LoginActivity.onCreate(LoginActivity.java:112) at android.app.Activity.performCreate(Activity.java:6010) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) at android.app.ActivityThread.access$800(ActivityThread.java:155) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5343) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 

Edit 3 : add part of code containing errors

 private void checkForNewBooking() { Bundle extras = getIntent().getExtras(); if (extras != null) { final String numConfirmation = extras.getString("NEWLY_BOOKED"); final String date[] = extras.getString("BOOKING_DATE").split("-"); //line 676 final String time[] = extras.getString("BOOKING_TIME").split(":"); final String club = extras.getString("BOOKING_CLUB"); final int hole = Integer.parseInt(extras.getString("BOOKING_HOLE")); 

Edit 4 : more code. Here is the onCreate () method. The call to the checkForNewBooking () method comes from there.

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); Log.d(TAG, "onCreate()"); mController = new ActivityController(this); // Setting server mode ((Globals) getApplication()).setServerInformation(SharedPrefManager.getServer(this)); // Hide auto-triggered keyboard this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); if (SharedPrefManager.isFirstRun(LoginActivity.this)) { SharedPrefManager.setFirstTimePrefs(LoginActivity.this, Utility.retreiveLanguage()); Log.d(TAG, "First run triggered."); } Bundle mBundle = getIntent().getExtras(); if (mBundle != null) { if (mBundle.getBoolean("PROCESS_KILLED")) { Toast.makeText(LoginActivity.this, R.string.ui_error_killedprocess, Toast.LENGTH_LONG).show(); } else { checkForNewBooking(); } } initializeUI(); WrappedLogger.setProvider(new LoggingProvider()); WrappedLogger.setMemoryLog(false); IPAddressInformation.getInstance().getIPAddress(); } 
+7
java android string null android-studio
source share
1 answer

So, this is not a complete super-super answer, but I was able to fix this error simply by changing the first if statement in checkForNewBooking (). Now this:

 if(extras.getString("BOOKING_DATE") != null) 

instead

 if(extras != null) 

I seriously don’t know why the program began with this. The class that I posted is the main one, from the very beginning, and therefore the information does not come from there. According to the comments that moved me in front of me, this method is designed to check whether the reservation has been completed in the past, which means that the information needed for BOOKING_DATE and BOOKING_TIME comes from another method after the reservation is completed.

Anyway, now it works! Thank you all for your help!

+1
source share

All Articles