當我執行此代碼時,我的程序獲得強制關閉..誰能告訴我..什麼是解決方案.. package com.test.sharedPreferences;共享首選項關閉
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class Sharedpreference extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = getSharedPreferences("Preference",MODE_WORLD_READABLE);
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("keyBoolean", true);
editor.putFloat("keyFloat", 1.0f);
editor.putInt("keyInt", 1);
editor.putLong("keyLong", 1000000L);
editor.putString("keyString", "Hello Android");
editor.commit();
// boolean dataFromPrefBool = pref.getBoolean("keyBoolean", false);
// float dataFromPrefflaot = pref.getFloat("keyFloat", 0.0f);
int dataFromPrefInt = pref.getInt("keyInt", 0);
// long dataFromPrefLong = pref.getLong("keyLong", 0);
// String dataFromPrefString = pref.getString("keyString", null);
TextView tv = new TextView(this);
tv.setText(dataFromPrefInt);
setContentView(tv);
}
}
粘貼logcat錯誤 – aromero 2011-12-26 13:38:34
確切的例外是什麼? logcat輸出請求 – 2011-12-26 13:42:19
其中是您的首選項名稱和聲明時的靜態字符串值。 – 2011-12-26 13:49:08