Может кто-нибудь помочь мне найти проблему?У меня есть MainActivity, что при переходе в режим остановки он вылетает.В коде 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)