0

My app only crush on device specific when open from shortcut icon.

I test on Samsung tablet with OS 4.2.2 and LG G4 with OS 6.0 which is ok. This issue cause on Robin phone with OS 6.0.

Edited:

I can't debug to pin point the issue cause when I run with debugger, app is running fine. I stop the running by debugger and open from shortcut icon, app is crush and the log show as per provided.

Please help me to find the root cause of this issue.

Below is the active log I receive when I try with the effected device.

 E/AndroidRuntime(5686): FATAL EXCEPTION: main
 E/AndroidRuntime(5686): Process: sg.gov.mfa, PID: 5686
 E/AndroidRuntime(5686): java.lang.RuntimeException: Unable to start activity ComponentInfo{sg.gov.mfa/sg.gov.mfa.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
 E/AndroidRuntime(5686):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
 E/AndroidRuntime(5686):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
 E/AndroidRuntime(5686):    at android.app.ActivityThread.access$900(ActivityThread.java:150)
 E/AndroidRuntime(5686):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
 E/AndroidRuntime(5686):    at android.os.Handler.dispatchMessage(Handler.java:102)
 E/AndroidRuntime(5686):    at android.os.Looper.loop(Looper.java:148)
 E/AndroidRuntime(5686):    at android.app.ActivityThread.main(ActivityThread.java:5417)
 E/AndroidRuntime(5686):    at java.lang.reflect.Method.invoke(Native Method)
`enter code here` E/AndroidRuntime(5686):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)

Manfest.xml

<activity
        android:label="@string/app_name"
        android:name=".MainActivity" android:screenOrientation="portrait" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />


        </intent-filter>
        <!-- 
        <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         -->

    </activity>

MainActivity.java

WebView splashFrame;
    RelativeLayout layoutBg;
    RelativeLayout layoutButton;
    Button btnMore, btnRegister, btnLocateMission, btnContactInfo, btnConsularInfo, btnTravelInfo, btnUsefulInfo, btnTwitter;  

     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main_layout);

            Display display = getWindowManager().getDefaultDisplay(); 
            int width = display.getWidth();
            int height = display.getHeight();

            DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(dm.widthPixels/dm.xdpi,2);
            double y = Math.pow(dm.heightPixels/dm.ydpi,2);
            double screenInches = Math.sqrt(x+y);
            Log.d("debug","Screen inches : " + screenInches);
            Log.d("WidthPx", "WidthPx : " + dm.widthPixels + " - HeightPx: " + dm.heightPixels);

            int ButtonLayoutHeight = (int)(dm.heightPixels*0.6);
            int ButtonLayoutWidth = dm.widthPixels;

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.layoutButton);
            btnMore = (Button) findViewById(R.id.btnMore);
            btnRegister = (Button) findViewById(R.id.btnRegister);
            btnLocateMission = (Button) findViewById(R.id.btnLocateMission);
            btnContactInfo = (Button) findViewById(R.id.btnContactInfo);
            btnConsularInfo = (Button) findViewById(R.id.btnConsularInfo);
            btnTravelInfo = (Button) findViewById(R.id.btnTravelInfo);
            btnUsefulInfo = (Button) findViewById(R.id.btnUsefulInfo);
            btnTwitter = (Button) findViewById(R.id.btnTwitter);

            int centreHorizon = (int)(ButtonLayoutWidth / 2);
            int centreVertical = (int)(ButtonLayoutHeight /2);

            int layout1_4Width = (int)(ButtonLayoutWidth / 4);
            int layout3_4Width = (int)(ButtonLayoutWidth*0.75);

            int layout1_4Height = (int)(ButtonLayoutHeight / 4);
            int layout3_4Height = (int)(ButtonLayoutHeight*0.75);

            Log.d("Layout Diemnsion", "Width:" + ButtonLayoutWidth + "Height:" + ButtonLayoutHeight + "CH:" + centreHorizon + 
            "CV:" + centreVertical + "1/4 W:" + layout1_4Width + "3/4W: " + layout3_4Width + "1/4H:" + layout1_4Height + "3/4H:" + layout3_4Height);

            int inchValue = 180/4;
            RelativeLayout.LayoutParams lpara = new RelativeLayout.LayoutParams(layout3_4Width-layout1_4Width, layout3_4Height-layout1_4Height); 
            lpara.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            lpara.addRule(RelativeLayout.CENTER_HORIZONTAL);
            lpara.topMargin=layout1_4Height;  
            btnMore.setLayoutParams(lpara);

            int inchValueWidth = 150/4;
            int inchValueHeight = 80/4;
            RelativeLayout.LayoutParams lpara1 = new RelativeLayout.LayoutParams((int)(centreHorizon*0.75), (layout1_4Height-10)); 
            lpara1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            lpara1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            btnRegister.setLayoutParams(lpara1);

            RelativeLayout.LayoutParams lpara2 = new RelativeLayout.LayoutParams((int)(centreHorizon*0.75), (layout1_4Height-10));
            lpara2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            lpara2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            btnLocateMission.setLayoutParams(lpara2);

            inchValueWidth = 80/4;
            inchValueHeight = 120/4;
            RelativeLayout.LayoutParams lpara3 = new RelativeLayout.LayoutParams(layout1_4Width, (centreVertical-layout1_4Height));
            lpara3.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            lpara3.addRule(RelativeLayout.BELOW, R.id.btnRegister);
            btnContactInfo.setLayoutParams(lpara3);

            RelativeLayout.LayoutParams lpara4 = new RelativeLayout.LayoutParams(layout1_4Width, (centreVertical-layout1_4Height));
            lpara4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            lpara4.addRule(RelativeLayout.BELOW, R.id.btnLocateMission);
            btnConsularInfo.setLayoutParams(lpara4);

            inchValueWidth = 100/4;
            inchValueHeight = 120/4;
            RelativeLayout.LayoutParams lpara5 = new RelativeLayout.LayoutParams(layout1_4Width, (layout3_4Height-centreVertical)+50);
            lpara5.addRule(RelativeLayout.BELOW, R.id.btnContactInfo);
            lpara5.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            btnTravelInfo.setLayoutParams(lpara5);

            RelativeLayout.LayoutParams lpara6 = new RelativeLayout.LayoutParams(layout1_4Width, (layout3_4Height-centreVertical)+50);
            lpara6.addRule(RelativeLayout.BELOW, R.id.btnConsularInfo);
            lpara6.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            btnUsefulInfo.setLayoutParams(lpara6);

            inchValueWidth = 150/4;
            inchValueHeight = 100/4;
            RelativeLayout.LayoutParams lpara7 = new RelativeLayout.LayoutParams(layout3_4Width-layout1_4Width, ButtonLayoutHeight-layout3_4Height);

            lpara7.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            lpara7.addRule(RelativeLayout.CENTER_HORIZONTAL);
            btnTwitter.setLayoutParams(lpara7);
    int rationHeight=(int)(screenInches*(350/4));
            Log.d("debug","Screen height:" + rationHeight); RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, ButtonLayoutHeight); //rationHeight
                layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                layoutParams2.bottomMargin = 20;
                rl.setLayoutParams(layoutParams2);

            Bundle extras = getIntent().getExtras();
            String value = "0";
            if (extras != null) {
                value = extras.getString(Constants.HOME_BUTTON_CLICK);
            }
            splashFrame = (WebView)findViewById(R.id.splashFrame);
            layoutButton = (RelativeLayout)findViewById(R.id.layoutButton); 

            if (value.equals("1"))
            {
                splashFrame.setVisibility(View.INVISIBLE);
                layoutButton.setVisibility(View.VISIBLE); 

            }
            else
            {
               splashFrame.setVisibility(View.VISIBLE);
                layoutButton.setVisibility(View.INVISIBLE); 

               splashFrame.setBackgroundColor(Color.WHITE);
               splashFrame.loadDataWithBaseURL("file:///android_res/drawable/", "<img align='middle' src='mfa_rot360_v02.gif' width='100%' />", "text/html", "utf-8", null);
               splashFrame.reload();

                    Handler handler = new Handler();

                // run a thread after 3 seconds to start the home screen
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        // make sure we close the splash screen so the user won't come back when it presses back key

                        //finish();
                        // start the home screen
                        splashFrame.setVisibility(View.INVISIBLE);
                        layoutButton.setVisibility(View.VISIBLE);   
                    }

                }, 9000);  
            }

        }
  • Could you change the line that reads `if (value.equals("1"))` to `if ("1".equals(value))` and let us know what happens? – Dr. Nitpick Jul 19 '16 at 03:00
  • I tried with those 3 device. Still the same result. – Thin Lai Wai Oo Jul 19 '16 at 03:27
  • try to `debug` the code and find the line which point that are crush .. – Harshad Pansuriya Jul 19 '16 at 03:51
  • I can't find the root cause by debugging. Cause when I debug app is running fine. I open again from shortcut icon while connecting the cable then app crush and show the log I provided as above. That's why I face difficult to pin point the root cause of this issue. – Thin Lai Wai Oo Jul 19 '16 at 06:30

0 Answers0