保存した設定を復元したいだけですが、エラーが発生します。共有設定でファイルの名前を変更できません
ログインクラス:
SharedPreferences.Editor editor = settings.edit();
editor.putString("session_id", session);
editor.commit();
Listクラス:
editor.putInt("channel_id", map.get(lv2.getItemAtPosition(arg2).toString()));
editor.commit();
メインクラス:
public class MainScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
TextView tv = (TextView) findViewById(R.id.mainscreen);
final SharedPreferences settings = getSharedPreferences("pref", 0);
String tmp= settings.getString("session_id", "Error") + "ID: " +String.valueOf(settings.getInt("channel_id", -1));
tv.setText(tmp);
setContentView(R.layout.mainscreen);
}
}
LogCat:
02-01 21:06:56.621: ERROR/ApplicationContext(25035): Couldn't rename file /dbdata/databases/android.skiptvad/shared_prefs/pref.xml to backup file /dbdata/databases/android.skiptvad/shared_prefs/pref.xml.bak
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): FATAL EXCEPTION: main
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.skiptvad/android.skiptvad.MainScreen}: java.lang.NullPointerException
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.os.Handler.dispatchMessage(Handler.java:99)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.os.Looper.loop(Looper.java:123)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at java.lang.reflect.Method.invokeNative(Native Method)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at java.lang.reflect.Method.invoke(Method.java:521)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): at dalvik.system.NativeStart.main(Native Method)
02-01 21:06:56.727: ERROR/AndroidRuntime(25035): Caused by: java.lang.NullPointerException
投稿したコード行で例外が発生することは確実ですか? – Falmarri
はい私はそう思います...フルクラスを投稿しました – user547995