我将一些数据保存到我的共享首选项中我可以访问它,直到我没有在marshmallow的应用程序权限中明确更改存储权限(在第一次允许或不允许的情况下无关紧要)。
案例1:当我在运行时更改存储权限以允许任何任务时,这是正常的,没有问题。
案例2:我再次尝试从共享首选项中读取,但这次我在应用程序权限中明确拒绝了存储权限,其崩溃时出现空指针异常,
请确认存储权限与外部存储或内部存储以及共享首选项有关。
记录错误:
**02-03 12:59:52.235: E/AndroidRuntime(6970): at android.os.AsyncTask$3.done(AsyncTask.java:309)**
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-03 12:59:52.235: E/AndroidRuntime(6970): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.lang.Thread.run(Thread.java:818)
02-03 12:59:52.235: E/AndroidRuntime(6970): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] com.necdisplay.IntlWirelessDataApp.common.SpecialClassMappingForSharedPreference.getData()' on a null object reference
02-03 12:59:52.235: E/AndroidRuntime(6970): at com.necdisplay.IntlWirelessDataApp.common.Function.compareAndUpdateModelName(Function.java:3549)
02-03 12:59:52.235: E/AndroidRuntime(6970): at com.necdisplay.IntlWirelessDataApp.common.Function.readModelName(Function.java:3665)
02-03 12:59:52.235: E/AndroidRuntime(6970): at com.necdisplay.IntlWirelessDataApp.common.Function.readServiceData(Function.java:2539)
02-03 12:59:52.235: E/AndroidRuntime(6970): at com.necdisplay.IntlWirelessDataApp.common.ReadWriteTask.doInBackground(ReadWriteTask.java:229)
02-03 12:59:52.235: E/AndroidRuntime(6970): at android.os.AsyncTask$2.call(AsyncTask.java:295)
02-03 12:59:52.235: E/AndroidRuntime(6970): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-03 12:59:52.235: E/AndroidRuntime(6970): ... 4 more
02-03 12:59:52.431: I/com.necdisplay.IntlWirelessDataApp.common.Utility(6970): getFileList
02-03 12:59:52.436: I/com.necdisplay.IntlWirelessDataApp.common.Utility(6970): getFileList
02-03 12:59:52.961: E/WindowManager(6970): android.view.WindowLeaked: Activity com.necdisplay.IntlWirelessDataApp.serviceconnection.ServiceConnection has leaked window com.android.internal.policy.PhoneWindow$DecorView{940db25 V.E...... R......D 0,0-959,192} that was originally added here
02-03 12:59:52.961: E/WindowManager(6970): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:368)
02-03 12:59:52.961: E/WindowManager(6970): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
02-03 12:59:52.961: E/WindowManager(6970): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
02-03 12:59:52.961: E/WindowManager(6970): at android.app.Dialog.show(Dialog.java:319)
02-03 12:59:52.961: E/WindowManager(6970): at com.necdisplay.IntlWirelessDataApp.common.ReadWriteTask.onPreExecute(ReadWriteTask.java:199)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:604)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.AsyncTask.execute(AsyncTask.java:551)
02-03 12:59:52.961: E/WindowManager(6970): at com.necdisplay.IntlWirelessDataApp.common.AsyncTaskForTagDetection.onPostExecute(AsyncTaskForTagDetection.java:205)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.AsyncTask.finish(AsyncTask.java:651)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.AsyncTask.-wrap1(AsyncTask.java)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.Handler.dispatchMessage(Handler.java:102)
02-03 12:59:52.961: E/WindowManager(6970): at android.os.Looper.loop(Looper.java:148)
02-03 12:59:52.961: E/WindowManager(6970): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-03 12:59:52.961: E/WindowManager(6970): at java.lang.reflect.Method.invoke(Native Method)
02-03 12:59:52.961: E/WindowManager(6970): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
答案 0 :(得分:0)
共享首选项不受用户应用权限afaik的影响。 根据文档https://developer.android.com/guide/topics/data/data-storage.html,即使在app目录中编写文件也不需要权限。
我怀疑SpecialClassMappingForSharedPreference
会导致问题。