SDカード「VCFFiles」内の特定のフォルダーからファイルを送信しようとしています。私はすべてのことを正しく行いました。もう一度機能しましたが、このアプリを実行すると、強制終了が表示されます。プロジェクトで行ったことは、ファイルが「VCFFiles」フォルダー内にリストされているため、5 つのラジオボタンとテキストを作成することです。ラジオボタンがクリックされると、送信ボタンをクリックすると編集テキストに入力された電子メールにそれぞれのvcfファイルが送信されます。以下は私のコードです:
public class SendActivity extends Activity{
private static final int PICK_IMAGE = 1;
EditText email;
TextView add_manage;
Button send;
RadioGroup vcfgroup;
RadioButton vcfButton;
String filepath="";
static File filevcf;
static Context mContext;
RadioButton vcf1;
RadioButton vcf2;
RadioButton vcf3;
RadioButton vcf4;
RadioButton vcf5;
ProgressDialog dialog;
String success;
String message;
String response;
String data;
File f;
String radio;
ArrayList<String> array;
// String state = Environment.getExternalStorageState();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.send);
email = (EditText)findViewById(R.id.emailid);
send = (Button)findViewById(R.id.send);
add_manage = (TextView)findViewById(R.id.add_manage);
vcfgroup = (RadioGroup)findViewById(R.id.vcfgroup);
vcf1 = (RadioButton)findViewById(R.id.vcf1);
vcf2 = (RadioButton)findViewById(R.id.vcf2);
vcf3 = (RadioButton)findViewById(R.id.vcf3);
vcf4 = (RadioButton)findViewById(R.id.vcf4);
vcf5 = (RadioButton)findViewById(R.id.vcf5);
send = (Button)findViewById(R.id.send);
// get selected radio button from radioGroup
radio = vcf1.getText().toString();
//get file names and set it in radio buttons
if(!isExternalStorageAvailable() || isExternalStorageReadOnly()){
}else{
new EventListTask2().execute(this);
}
//send vcf files to the server
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int selectedId = vcfgroup.getCheckedRadioButtonId();
vcf1 =(RadioButton)findViewById(selectedId);
try{
f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/VCFFiles/"+vcf1.getText().toString());
filepath = f.getPath();
if(email.getText().length()!=0){
dialog = ProgressDialog.show(SendActivity.this,
"Sending", "Please wait...", true);
new EventListTask1().execute();
}else{
Toast.makeText(getApplicationContext(), "You may have not entered emailid or selected wrong file!!", Toast.LENGTH_LONG).show();
}
}catch(Exception e){
}
}
});
add_manage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in = new Intent(SendActivity.this,AddContactActivity.class);
startActivity(in);
}
});
}
public ArrayList<String> GetFiles() {
ArrayList<String> MyFiles = new ArrayList<String>();
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/VCFFiles");
f.mkdirs();
File[] files = f.listFiles();
if (files.length == 0)
return null;
else {
for (int i=0; i<5; i++)
if(files[i].getPath().endsWith(".vcf")){
MyFiles.add(files[i].getName());
}
}
return MyFiles;
}
EventListTask2 クラス内で、GetFiles() 関数を使用して「VCFFIles」からファイルをフェッチし、名前を各ラジオボタンの名前に関連付けています。内部のコードを以下に示します。
RadioButton radioset[] = {vcf1, vcf2, vcf3, vcf4, vcf5};
if(GetFiles().size()!=0){
array=GetFiles();
for(int i=0;i<array.size();i++){
radioset[i].setText(array.get(i));
}}else{
Toast.makeText(getApplicationContext(), "You have no vcf files saved", Toast.LENGTH_LONG).show();
}
以下はアプリのログです。
03-18 18:41:17.410: E/AndroidRuntime(1598): FATAL EXCEPTION: main
03-18 18:41:17.410: E/AndroidRuntime(1598): java.lang.NullPointerException
03-18 18:41:17.410: E/AndroidRuntime(1598): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:321)
03-18 18:41:17.410: E/AndroidRuntime(1598): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:1)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.os.Looper.loop(Looper.java:123)
03-18 18:41:17.410: E/AndroidRuntime(1598): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 18:41:17.410: E/AndroidRuntime(1598): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 18:41:17.410: E/AndroidRuntime(1598): at java.lang.reflect.Method.invoke(Method.java:521)
03-18 18:41:17.410: E/AndroidRuntime(1598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 18:41:17.410: E/AndroidRuntime(1598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 18:41:17.410: E/AndroidRuntime(1598): at dalvik.system.NativeStart.main(Native Method)
03-18 18:53:12.560: E/IOException(1648): IO error: /mnt/sdcard/VCFFiles/Empty (Permission denied)
03-18 18:53:12.560: E/IOException(1648): java.io.FileNotFoundException: /mnt/sdcard/VCFFiles/Empty (Permission denied)
03-18 18:53:12.560: E/IOException(1648): at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
03-18 18:53:12.560: E/IOException(1648): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
03-18 18:53:12.560: E/IOException(1648): at java.io.FileInputStream.<init>(FileInputStream.java:82)
03-18 18:53:12.560: E/IOException(1648): at com.example.mycontactdetails.SendActivity$Utils.PostDataToFavoriteUser(SendActivity.java:182)
03-18 18:53:12.560: E/IOException(1648): at com.example.mycontactdetails.SendActivity$EventListTask1.doInBackground(SendActivity.java:310)
03-18 18:53:12.560: E/IOException(1648): at com.example.mycontactdetails.SendActivity$EventListTask1.doInBackground(SendActivity.java:1)
03-18 18:53:12.560: E/IOException(1648): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 18:53:12.560: E/IOException(1648): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-18 18:53:12.560: E/IOException(1648): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-18 18:53:12.560: E/IOException(1648): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-18 18:53:12.560: E/IOException(1648): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-18 18:53:12.560: E/IOException(1648): at java.lang.Thread.run(Thread.java:1096)
03-18 18:53:12.630: E/AndroidRuntime(1648): FATAL EXCEPTION: main
03-18 18:53:12.630: E/AndroidRuntime(1648): java.lang.NullPointerException
03-18 18:53:12.630: E/AndroidRuntime(1648): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:321)
03-18 18:53:12.630: E/AndroidRuntime(1648): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:1)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.os.Looper.loop(Looper.java:123)
03-18 18:53:12.630: E/AndroidRuntime(1648): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 18:53:12.630: E/AndroidRuntime(1648): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 18:53:12.630: E/AndroidRuntime(1648): at java.lang.reflect.Method.invoke(Method.java:521)
03-18 18:53:12.630: E/AndroidRuntime(1648): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 18:53:12.630: E/AndroidRuntime(1648): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 18:53:12.630: E/AndroidRuntime(1648): at dalvik.system.NativeStart.main(Native Method)
03-18 19:00:13.010: E/IOException(1676): IO error: /mnt/sdcard/VCFFiles/Empty (Permission denied)
03-18 19:00:13.010: E/IOException(1676): java.io.FileNotFoundException: /mnt/sdcard/VCFFiles/Empty (Permission denied)
03-18 19:00:13.010: E/IOException(1676): at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
03-18 19:00:13.010: E/IOException(1676): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
03-18 19:00:13.010: E/IOException(1676): at java.io.FileInputStream.<init>(FileInputStream.java:82)
03-18 19:00:13.010: E/IOException(1676): at com.example.mycontactdetails.SendActivity$Utils.PostDataToFavoriteUser(SendActivity.java:183)
03-18 19:00:13.010: E/IOException(1676): at com.example.mycontactdetails.SendActivity$EventListTask1.doInBackground(SendActivity.java:311)
03-18 19:00:13.010: E/IOException(1676): at com.example.mycontactdetails.SendActivity$EventListTask1.doInBackground(SendActivity.java:1)
03-18 19:00:13.010: E/IOException(1676): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 19:00:13.010: E/IOException(1676): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-18 19:00:13.010: E/IOException(1676): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-18 19:00:13.010: E/IOException(1676): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-18 19:00:13.010: E/IOException(1676): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-18 19:00:13.010: E/IOException(1676): at java.lang.Thread.run(Thread.java:1096)
03-18 19:00:13.090: E/AndroidRuntime(1676): FATAL EXCEPTION: main
03-18 19:00:13.090: E/AndroidRuntime(1676): java.lang.NullPointerException
03-18 19:00:13.090: E/AndroidRuntime(1676): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:322)
03-18 19:00:13.090: E/AndroidRuntime(1676): at com.example.mycontactdetails.SendActivity$EventListTask1.onPostExecute(SendActivity.java:1)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.os.Looper.loop(Looper.java:123)
03-18 19:00:13.090: E/AndroidRuntime(1676): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-18 19:00:13.090: E/AndroidRuntime(1676): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 19:00:13.090: E/AndroidRuntime(1676): at java.lang.reflect.Method.invoke(Method.java:521)
03-18 19:00:13.090: E/AndroidRuntime(1676): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-18 19:00:13.090: E/AndroidRuntime(1676): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-18 19:00:13.090: E/AndroidRuntime(1676): at dalvik.system.NativeStart.main(Native Method)
何が問題なのかわかりませんか?どんな助けでも感謝します。