我的應用程序中的權限有問題。它看起來像我的應用程序沒有權限在存儲上創建文件。Android openFileOutput - 無權創建存儲
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos;
try
{
fos = getApplicationContext()
.openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
在我的主類的onCreate處理程序,我總是得到:
06-02 13:23:52.996: WARN/ApplicationContext(6278): Unable to create files directory
06-02 13:23:54.203: WARN/System.err(6278): java.lang.NullPointerException
06-02 13:23:54.226: WARN/System.err(6278): at android.app.ContextImpl.openFileOutput(ContextImpl.java:464)
06-02 13:23:54.234: WARN/ActivityManager(2470): Activity idle timeout for HistoryRecord{485ebe10 com.servision.svclient/.Main}
06-02 13:23:54.257: WARN/System.err(6278): at android.content.ContextWrapper.openFileOutput(ContextWrapper.java:158)
06-02 13:23:54.273: WARN/System.err(6278): at com.servision.svclient.Main.onCreate(Main.java:59)
06-02 13:23:54.277: WARN/System.err(6278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-02 13:23:54.285: WARN/System.err(6278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-02 13:23:54.293: WARN/System.err(6278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-02 13:23:54.296: WARN/System.err(6278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-02 13:23:54.304: WARN/System.err(6278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-02 13:23:54.312: WARN/System.err(6278): at android.os.Handler.dispatchMessage(Handler.java:99)
06-02 13:23:54.320: WARN/System.err(6278): at android.os.Looper.loop(Looper.java:123)
06-02 13:23:54.324: WARN/System.err(6278): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-02 13:23:54.332: WARN/System.err(6278): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 13:23:54.336: WARN/System.err(6278): at java.lang.reflect.Method.invoke(Method.java:521)
06-02 13:23:54.343: WARN/System.err(6278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-02 13:23:54.355: WARN/System.err(6278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-02 13:23:54.359: WARN/System.err(6278): at dalvik.system.NativeStart.main(Native Method)
響應。
我相信它在我的項目定義中非常簡單。但我無法弄清楚它是什麼。
如果我創建另一個項目並將相同的代碼放入它,它工作正常。
我的清單文件看起來是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.servision.svclient"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<application android:icon="@drawable/main" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".Main" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StreamActivity" android:label="@string/app_name"/>
<activity android:name=".MainActivity"/>
<activity android:name=".GatewayList"/>
<activity android:name=".StatisticsActivity"/>
<activity android:name=".SettingsActivity"/>
<activity android:name=".MapsActivity"/>
<activity android:name=".AboutActivity"/>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Main.java的第59行是什麼 – 2011-06-02 10:47:06
我真的不認爲內部存儲需要權限。發佈的堆棧跟蹤是否已滿?或者你正在省略線條。 – doNotCheckMyBlog 2011-06-02 10:53:38
沒有android.permission.WRITE_INTERNAL_STORAGE – 2013-10-29 15:10:30