gpt4 book ai didi

android - Android在检查首选项时崩溃

转载 作者:行者123 更新时间:2023-12-03 17:42:46 24 4
gpt4 key购买 nike

有人可以帮我找到问题吗?
我有MainActivity,当我停止 Activity 模式时,它崩溃了。
在MainActivity.setPref()的代码中,该代码包含:

public void setPref(Context context){
boolean CheckboxPreference3=false;
boolean CheckboxPreference6=true;
boolean CheckboxPreference9=true;
boolean CheckboxPreference91=true;
boolean CheckboxPreference10=true;
boolean CheckboxPreference11=true;

String IntPreference10="0";
String CheckboxPreference4 = "";
boolean CheckboxPreference5=false;

SharedPreferences prefs2 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference3 = prefs2.getBoolean("english", true);
if (CheckboxPreference3){
VarsN.english=true;
}else{
VarsN.english=false;
}

SharedPreferences prefs5 = PreferenceManager.getDefaultSharedPreferences(context);
boolean bool=true;
if (VarsN.Titl1.contains("lite")){
bool=false;
}
CheckboxPreference6 = prefs5.getBoolean("dynamic", bool);

if (CheckboxPreference6){
Vars.Dynamic=true;
}else{
Vars.Dynamic=false;
}

SharedPreferences prefs8 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference9 = prefs8.getBoolean("il", false);
if (CheckboxPreference9){
Vars.Israeli=true;
}else{
Vars.Israeli=false;
}
SharedPreferences prefs81 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference91 = prefs81.getBoolean("jer", false);
if (CheckboxPreference91){
Vars.Jerusalem=true;
}else{
Vars.Jerusalem=false;
}

SharedPreferences prefs51 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference5 = prefs51.getBoolean("turn", false);
if (CheckboxPreference5){
Vars.noRotat=true;
}else{
Vars.noRotat=false;
}

SharedPreferences prefs9 = PreferenceManager.getDefaultSharedPreferences(context);
IntPreference10 = prefs9.getString("PrefBear", "0");
Vars.bearing=Integer.valueOf(IntPreference10);

SharedPreferences prefs4 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference4 = prefs4.getString("cities", "");
String fileName="prefsLonLat";
SharedPreferences prefs1 = getSharedPreferences(fileName, MODE_PRIVATE);
Vars.lat = Double.valueOf(prefs1.getString("lat", "40.65"));
Vars.lon = Double.valueOf(prefs1.getString("lon", "-73.94"));

if (CheckboxPreference4!=""){
if (Vars.lat!=40.6501038&&Vars.lon!=-73.94){
Vars.City=CheckboxPreference4.trim();
}else{
Vars.City="New York, USA";
}

}else{//Bad string
Vars.City="New York, USA";
}

SharedPreferences prefs10 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference10 = prefs10.getBoolean("gp", true);
if (CheckboxPreference10){
Vars.GP=true;
}else{
Vars.GP=false;
}

SharedPreferences prefs11 = PreferenceManager.getDefaultSharedPreferences(context);
CheckboxPreference11 = prefs11.getBoolean("hsys", false);
if (CheckboxPreference11){
Vars.HSys=true;
}else{
Vars.HSys=false;
}
}

我得到:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.yyy/com.xxx.yyy.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.xxx.yyy.MainActivity.setPref(MainActivity.java:325)
at com.xxx.yyy.MainActivity.onCreate(MainActivity.java:499)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

最佳答案

根据失败的行以及您引用上面的VarsN的事实,Titl1为空。

关于android - Android在检查首选项时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063847/

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