无法从sharedpreferences文件中获取所有键和值

时间:2016-02-21 11:37:55

标签: android dictionary sharedpreferences

每当我试图在Map中存储密钥时,我都会收到错误并且文件强制停止..

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_date_detail_activity);


        //getting name of file from intent
        Intent in = getIntent();

        String date= in.getStringExtra("Date");

 //Date is the file name of preference i got from there is no error in this line
        SharedPreferences sharedPreferences = getSharedPreferences(date, MODE_PRIVATE);

        //These line causing error
        Map<String,?> keys = sharedPreferences.getAll();

        for(Map.Entry<String,?> entry : keys.entrySet()){
            Log.d("map values", entry.getKey() + ": " +
                    entry.getValue().toString());
        }

    }

这些是我得到的错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anshuman.attendance/com.anshuman.attendance.Date_detail_activity}: java.lang.IllegalArgumentException: File android.support.v7.widget.AppCompatTextView{2355dc9a V.ED.... ........ 0,0-984,144 #1020014 android:id/text1}.xml contains a path separator
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:135)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at java.lang.reflect.Method.invoke(Method.java:372)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                                        Caused by: java.lang.IllegalArgumentException: File android.support.v7.widget.AppCompatTextView{2355dc9a V.ED.... ........ 0,0-984,144 #1020014 android:id/text1}.xml contains a path separator
                                                                           at android.app.ContextImpl.makeFilename(ContextImpl.java:2374)
                                                                           at android.app.ContextImpl.getSharedPrefsFile(ContextImpl.java:904)
                                                                           at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:934)
                                                                           at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:169)
                                                                           at com.anshuman.attendance.Date_detail_activity.onCreate(Date_detail_activity.java:32)
                                                                           at android.app.Activity.performCreate(Activity.java:5933)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
                                                                           at android.app.ActivityThread.access$800(ActivityThread.java:144) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5221) 
                                                                           at java.lang.reflect.Method.invoke(Native Method) 
                                                                           at java.lang.reflect.Method.invoke(Method.java:372) 

0 个答案:

没有答案