Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashes when run from phone but works fine when launched from computer

I've been able after 3 days of work to make an old app run on my device! But only when the command comes from my computer...

I explain. When I launch the app from Android Studio on my phone, it launches fine, which is great. But when I launch it directly from my phone, I get in Catlog that a String is null. I don't understand what could cause this.. It works fine when the app is started from my computer but not from the phone...

Please, help!

Edit 1: Add AndroidManifest.xml activities

<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 a part of the code containing the 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 for the method checkForNewBooking() 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();
}
like image 720
dequec64 Avatar asked Jan 08 '16 20:01

dequec64


1 Answers

So it's not a complete great super answer, but I've been able to fix this bug simply by changing the first if statement in the checkForNewBooking(). Now it is:

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

instead of

if(extras != null)

I seriously don't know why the program started with this.. The class I posted parts of is the main one, launching at the start and so information don't come from there. According to the comments the guy before me left, this method is meant to check if a booking has been completed in the past, meaning maybe that the information required for BOOKING_DATE and BOOKING_TIME comes from another method once a booking has been completed.

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

like image 101
dequec64 Avatar answered Oct 20 '22 13:10

dequec64