gpt4 book ai didi

安卓:随机异常

转载 作者:行者123 更新时间:2023-11-30 03:53:09 25 4
gpt4 key购买 nike

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

这是堆栈:

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

似乎有时, Activity 无法绘制某些资源或打开原始文件...谢谢...

这里是“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);
}

最佳答案

Activity Activity myactivit 不包含 ID 为 BtnResId 的资源。

关于安卓:随机异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com