Java 公共外部存储器
我试图将一个txt文件保存到公共外部存储器 文件清单Java 公共外部存储器,java,android,Java,Android,我试图将一个txt文件保存到公共外部存储器 文件清单 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hikilam.publicprivateexternalstorage"> <application android:allowBackup="true" android:icon="@mipma
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hikilam.publicprivateexternalstorage">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
错误代码
02-29 20:53:19.511 4696-4696/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hikilam.publicprivateexternalstorage, PID: 4696
java.lang.IllegalStateException: Could not execute method for android:onClick
publicStorage()方法是在哪里定义的?为什么要将视图传递到此函数中?另外,在发布堆栈跟踪时,请将整个堆栈跟踪发布到文件中。@DougStevensonMainActivity@KonstantinVolkov我还有别的事需要它
public void publicStorage(View view) {
String data = username.getText().toString();
File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file1 = new File(file, "file.txt");
FileOutputStream fileOutputStream=null;
try {
fileOutputStream=new FileOutputStream(file1);
fileOutputStream.write(data.getBytes());
Toast.makeText(this,"Stored Succeful"+file1.getAbsolutePath(),Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
02-29 20:53:19.511 4696-4696/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hikilam.publicprivateexternalstorage, PID: 4696
java.lang.IllegalStateException: Could not execute method for android:onClick