致命异常:异步#5执行doInBackground()时发生错误

时间:2014-05-11 22:01:21

标签: java android

这是我的代码。当我尝试运行它时,它给了我错误 致命异常:异步#5 java.lang.RuntimeException:执行doInBackground()时发生错误。

问题究竟是什么问题?我无法得到它。如有任何帮助,将不胜感激

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        targetUri = data.getData();
        textTargetUri.setText(getRealPath(targetUri));
}

// And to convert the image URI to the direct file system path of the image file
public String getRealPath(Uri contentUri) {

        // can post image
        String [] proj={MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery( contentUri,
                        proj, // Which columns to return
                        null,       // WHERE clause; which rows to return (all rows)
                        null,       // WHERE clause selection arguments (none)
                        null); // Order-by clause (ascending by name)
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();

        return cursor.getString(column_index);
}

public class EncodeAndDecodeTask extends AsyncTask<Void, Void, Void>{

        byte[] key;
        Bitmap image;
        String message;

        protected void onPreExecute(){
                pd = ProgressDialog.show(TextTab.this, "Working..", "Working on your image.", true, false);
        }
        @Override
        protected Void doInBackground(Void... params){
                ReturnActivity get;
                if (radioGroup.getCheckedRadioButtonId() == (R.id.radio0)){
                        get = EActivity.encodeText(textTargetUri.getText().toString(), writeTo, editText.getText().toString());
                        key = (byte[]) get.second;
                        image = (Bitmap) get.first;
                        imageView.setImageBitmap(image);
                }
                else if (radioGroup.getCheckedRadioButtonId() == 1){
                        message = EActivity.decodeText(textTargetUri.getText().toString(), editText2.getText().toString());
                }
                return null;
        }

        protected void onPostExecute(Void useless){
                pd.dismiss();
                final AlertDialog alertDialog = new AlertDialog.Builder(TextTab.this).create();
                alertDialog.setMessage(writeTo);
                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                         // alertDialog.dismiss();
                    } });

                alertDialog.show();
        }
}

我的日志猫:

05-11 17:49:16.324: E/AndroidRuntime(7543): FATAL EXCEPTION: AsyncTask #5
05-11 17:49:16.324: E/AndroidRuntime(7543): java.lang.RuntimeException: An error occured while executing doInBackground()
05-11 17:49:16.324: E/AndroidRuntime(7543):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.lang.Thread.run(Thread.java:841)
05-11 17:49:16.324: E/AndroidRuntime(7543): Caused by: java.lang.NullPointerException
05-11 17:49:16.324: E/AndroidRuntime(7543):     at com.minor.AESActivity.generateKey(AESActivity.java:49)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at com.minor.EActivity.encodeText(EActivity.java:55)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at com.minor.TextTab$EncodeAndDecodeTask.doInBackground(TextTab.java:111)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at com.minor.TextTab$EncodeAndDecodeTask.doInBackground(TextTab.java:1)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-11 17:49:16.324: E/AndroidRuntime(7543):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-11 17:49:16.324: E/AndroidRuntime(7543):     ... 4 more
05-11 17:49:17.104: I/Choreographer(7543): Skipped 39 frames!  The application may be doing too much work on its main thread.
05-11 17:49:19.985: I/Process(7543): Sending signal. PID: 7543 SIG: 9

2 个答案:

答案 0 :(得分:0)

这里似乎有null值:

get = EActivity.encodeText(textTargetUri.getText().toString(), writeTo, editText.getText().toString());

我会调试,并找出null的值。

答案 1 :(得分:0)

你应该在doinbackground()之外声明你的观点。 删除R.id.radio并在do inbackground

之外声明它