1

在我的应用程序上更改活动后,有时我会遇到异常,我不知道可能是什么问题。此异常不会发生在相同的活动中(而是随机的)和调用的不同函数中。

这是堆栈:

12-11 10:48:34.677: E/AndroidRuntime(479): FATAL EXCEPTION: main
12-11 10:48:34.677: E/AndroidRuntime(479): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apia.selfnettest/com.apia.selfnettest.TabPayments}: java.lang.NullPointerException
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.os.Looper.loop(Looper.java:130)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread.main(ActivityThread.java:3683)
12-11 10:48:34.677: E/AndroidRuntime(479):  at java.lang.reflect.Method.invokeNative(Native Method)
12-11 10:48:34.677: E/AndroidRuntime(479):  at java.lang.reflect.Method.invoke(Method.java:507)
12-11 10:48:34.677: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-11 10:48:34.677: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-11 10:48:34.677: E/AndroidRuntime(479):  at dalvik.system.NativeStart.main(Native Method)
12-11 10:48:34.677: E/AndroidRuntime(479): Caused by: java.lang.NullPointerException
12-11 10:48:34.677: E/AndroidRuntime(479):  at com.apia.utils.LibLayout.setDisplayMenuContent(LibLayout.java:557)
12-11 10:48:34.677: E/AndroidRuntime(479):  at com.apia.selfnettest.TabPayments.onCreate(TabPayments.java:167)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-11 10:48:34.677: E/AndroidRuntime(479):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-11 10:48:34.677: E/AndroidRuntime(479):  ... 11 more

似乎有时,活动无法提取某些资源或打开原始文件...谢谢...

这里是“setDisplayMenuContent”的代码:

public static void setDisplayMenuContent(ArrayList<?> localTabMenu_records, Display display, 
        Activity myactivity, int myId, int BtnResId ) {

    int width = display.getWidth(); 
    int height = display.getHeight(); 
    int N_Tab=3;
    Button btnSelButton = null;
    Button btnUnSelButton = null;

    int Ntab= Math.min(N_Tab, 4);

    if (Ntab>0)
    {


        Button btn1 = null;
        Button btn12= null;
        Button btn2= null;
        Button btn22= null;
        Button btn3= null;  
        Button btn32 = null;
        Button btn0off= null;
        Button btn00off= null;
        Button btn1off= null;
        Button btn11off= null;
        Button btn2off= null;
        Button btn22off= null;


        if (LibController.appLogged) {
            /*ONLINE*/
            btn1 = (Button) myactivity.findViewById(R.id.menu1);
            btn12 = (Button) myactivity.findViewById(R.id.menu12);
            btn2 = (Button) myactivity.findViewById(R.id.menu2);
            btn22 = (Button) myactivity.findViewById(R.id.menu22);
            btn3 = (Button) myactivity.findViewById(R.id.menu3);    
            btn32 = (Button) myactivity.findViewById(R.id.menu32); 
        }else{
            /*OFFLINE*/
            btn0off = (Button) myactivity.findViewById(R.id.menu0off);
            btn00off = (Button) myactivity.findViewById(R.id.menu00off);
            btn1off = (Button) myactivity.findViewById(R.id.menu1off);
            btn11off = (Button) myactivity.findViewById(R.id.menu11off);
            btn2off = (Button) myactivity.findViewById(R.id.menu2off);
            btn22off = (Button) myactivity.findViewById(R.id.menu22off);

        }

        if(localTabMenu_records != null && localTabMenu_records.size() > 0){
            for(int i=0; i<localTabMenu_records.size();i++){    
                RecordTabMenu myRec = (RecordTabMenu) localTabMenu_records.get(i);

                if (LibController.appLogged) {
                    // *********** ONLINE ************  
                    if (myRec.getIdTab().equals("TabWelcome")) 
                    {
                        if (BtnResId == R.id.menu1) {
                            btnSelButton=btn1;
                            btnUnSelButton=btn12;
                        }
                        else {
                            btnSelButton=btn12;
                            btnUnSelButton=btn1;
                        }
                    }
                    else if (myRec.getIdTab().equals("TabAccount"))
                    {
                        if (BtnResId == R.id.menu2) {
                            btnSelButton=btn2;
                            btnUnSelButton=btn22;
                        }
                        else {
                            btnSelButton=btn22;
                            btnUnSelButton=btn2;
                        }
                    }
                    else if (myRec.getIdTab().equals("TabPayments"))
                    {
                        if (BtnResId == R.id.menu3) {
                            btnSelButton=btn3;
                            btnUnSelButton=btn32;
                        }
                        else {
                            btnSelButton=btn32;
                            btnUnSelButton=btn3;
                        }       
                    }    

                }else {

                    // *********** OFFLINE ************
                    if(myRec.getIdTab().equals("TabMainClass"))
                    {
                        if (BtnResId == R.id.menu0off) {
                            btnSelButton=btn0off;
                            btnUnSelButton=btn00off;
                        }
                        else {
                            btnSelButton=btn00off;
                            btnUnSelButton=btn0off;
                        }
                    }
                    else if (myRec.getIdTab().equals("TabContact")) 
                    {
                        if (BtnResId == R.id.menu1off) {
                            btnSelButton=btn1off;
                            btnUnSelButton=btn11off;
                        }
                        else {
                            btnSelButton=btn11off;
                            btnUnSelButton=btn1off;
                        }
                    }else if (myRec.getIdTab().equals("TabInfo"))   
                    {
                        if (BtnResId == R.id.menu2off) {
                            btnSelButton=btn2off;
                            btnUnSelButton=btn22off;
                        }
                        else {
                            btnSelButton=btn22off;
                            btnUnSelButton=btn2off;
                        }
                    }
                }

                String myCaptio = myRec.getTitleTab();
                setButtonPropertiesForLayout(myactivity, i, btnSelButton, height, width, Ntab , myCaptio);

                if (btnUnSelButton != null) {
                    btnUnSelButton.getLayoutParams().width = 0;  // INVISIBLE
                }

            };
        }       

    }


    Button myBtn = (Button) myactivity.findViewById(BtnResId);
    myBtn.setBackgroundResource(R.drawable.menusel);
}
4

1 回答 1

1

该活动Activity myactivit不包含具有 id 的资源BtnResId

于 2012-12-11T10:23:26.550 回答