ユーザーがいくつかのチェックボックスを選択し、送信を押すと、選択されたすべてのチェックボックスに文が含まれる.txtファイルが作成されるアプリを作成しようとしています。
これのビルドが1回成功し、ファイルが適切に作成されましたが、電子メールに添付できるように、アクセス可能なファイルの場所に保存する必要があります。アクセス可能である限り、どこに保存するかはあまり気にしません。
次のコードは、Android仮想デバイスと私のGalaxy 2で実行するとクラッシュを引き起こします。このアプリケーションは、後のアプリの概念実証です。ありがとうございました。
@Override
public void onClick(View v)
{
String nochartOutput = " ";
if (sitting.isChecked())
nochartOutput += "The patient was sitting in a chair. ";
if (breathing.isChecked())
nochartOutput += "The patient was breathing. ";
if (alert.isChecked())
nochartOutput += "The patient was alert. ";
FileOutputStream fOut = null;
File sdDir = Environment.getExternalStorageDirectory();
try {
fOut = openFileOutput(sdDir + "/AutoWriter/samplefile.txt",MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
OutputStreamWriter osw = new OutputStreamWriter(fOut);
try {
osw.write(nochartOutput);
osw.flush();
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
03-04 18:39:53.604:W / dalvikvm(10453):threadid = 1:キャッチされない例外でスレッドが終了します(group = 0x40c211f8)
03-04 18:39:53.624:E / AndroidRuntime(10453):致命的な例外:メイン
03-04 18:39:53.624:E / AndroidRuntime(10453):java.lang.IllegalArgumentException:ファイル/mnt/sdcard/samplefile.txtにパス区切り文字が含まれています
03-04 18:39:53.624:E / AndroidRuntime(10453):android.app.ContextImpl.makeFilename(ContextImpl.java:1703)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.app.ContextImpl.openFileOutput(ContextImpl.java:723)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.content.ContextWrapper.openFileOutput(ContextWrapper.java:165)
03-04 18:39:53.624:E / AndroidRuntime(10453):com.example.com.dresdor.autowriter.MainActivity $ 1.onClick(MainActivity.java:48)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.view.View.performClick(View.java:3620)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.view.View $ PerformClick.run(View.java:14292)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.os.Handler.handleCallback(Handler.java:605)で
03-04 18:39:53.624:E / AndroidRuntime(10453):android.os.Handler.dispatchMessage(Handler.java:92)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.os.Looper.loop(Looper.java:137)
03-04 18:39:53.624:E / AndroidRuntime(10453):android.app.ActivityThread.main(ActivityThread.java:4507)
03-04 18:39:53.624:E / AndroidRuntime(10453):java.lang.reflect.Method.invokeNative(ネイティブメソッド)
03-04 18:39:53.624:E / AndroidRuntime(10453):java.lang.reflect.Method.invoke(Method.java:511)で
03-04 18:39:53.624:E / AndroidRuntime(10453):com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:790)
03-04 18:39:53.624:E / AndroidRuntime(10453):com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-04 18:39:53.624:E / AndroidRuntime(10453):dalvik.system.NativeStart.main(ネイティブメソッド)