尝试调用虚方法' boolean java.lang.String.equals(java.lang.Object)'在null对象引用上

时间:2016-07-19 02:57:14

标签: java android nullpointerexception

我的应用只会在从快捷方式图标打开时粉碎特定设备。

我在带有OS 4.2.2的三星平板电脑和带有OS 6.0的LG G4上进行测试即可。 这个问题导致Robin手机上有OS 6.0。

编辑:

当我使用调试器运行时,我无法调试以查明问题原因,应用程序正常运行。我通过调试器停止运行并从快捷方式图标打开,应用程序粉碎,日志显示按照提供。

请帮我找出这个问题的根本原因。

以下是我尝试使用受影响的设备时收到的活动日志。

 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);  
            }

        }

0 个答案:

没有答案