onActivityResult在DoInBackground中不使用Runtimeexception

时间:2017-12-04 10:36:56

标签: java android android-intent android-activity

我有一个活动用startActivityForResult调用另一个活动(绘图),但当我完成另一个活动时,应用程序崩溃,然后输入onActivityResult(第一个活动),RuntimeException

这就是我调用Draw活动的方式:

fileUri = getOutputMediaFileUri(wo.getWorkOrder() + " - IMG");     
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(intent, strategy.ordinal());

在新活动中:

Bitmap bmp = sign.getBitmapImage();
Intent doc = IntentFactory.createWorkOrderDocumentsTable(this);
doc.putExtra("signature", bmp);
setResult(RESULT_OK, doc);

AsyncTask(我这次没有使用这个异步任务,但它是logcat中提到的asynctask):

公共类LoadWorkOrderInfo扩展了AsyncTask {

    ProgressDialog progress;
    Context context;
    Application app = Application.getInstance();
    String woExecution;

    public LoadWorkOrderInfo(Context context) {
        this.context = context;
    }

    protected void onPreExecute() {


    }

    protected Integer doInBackground(Integer... paramss) {

        try {
            CompanyQueries cQ = CompanyQueriesFactory.createCompanyQueriesFactory();
            LaborRecordQueries lrq = LaborRecordQueriesFactory.createWorkOrderQueriesFactory();
            WorkTypeQueries wtq = WorkTypeQueriesFactory.createWorkTypeQueriesFactory();
            WorkRequestTypeQueries wrtq = WorkRequestTypeQueriesFactory.createWorkRequestTypeQueriesFactory();

            String parameterValue = cQ.getCompanyParameterValue(601);

            if (parameterValue.equals("1")) {

                woExecution = app.getExecutionWOState().getWorkOrderState();
                app.setUseLaborRecord(parameterValue.equals("1"));
            } else {
                woExecution = null;
                app.setUseLaborRecord(parameterValue.equals("1"));
            }

                if (wo != null) {
                    app.setWorkOrder(wo);

                    // Verifica se OS est? em execu??o
                    if (wo.getWorkOrderState().equals(
                            app.getExecutionWOState().getWorkOrderState())) {
                        isWOInExecution = true;

                        // Carrega LaborRecord para preparar finaliza??o da OS
                        lre = lrq.selectLaborRecordByWorkOrderAndWorker(wo,
                                app.getUser());
                    }
                }
                else
                    return 3;

                workTypeName = wtq.selectWorkTypeName(app.getWorkOrder().getWorkType());
                workRequestTypeName = wrtq.selectWorkRequestTypeName(app.getWorkOrder().getWorkRequestType());

                return 1;
            }
            else
            {
                WorkOrder workOrder = app.getWorkOrder();

                if(workOrder == null)
                    return 2;

                else if (!app.useLaborRecord())
                {


                    return 4;
                }
                else
                    return 1;
            }
    }

    protected void onPostExecute(Integer result) {

        WorkOrder wo = app.getWorkOrder();

        if (result == 1) {
            try {
                if (app.useLaborRecord() && (wo == null || wo.getWorkOrderState().equals(woExecution))) {
                    LaborRecordThread lrThread = new LaborRecordThread();
                    lrThread.start();
                    lrThread.join();
                } else {
                    WorkOrder workOrder = app.getWorkOrder();

                    if (workOrder == null) {
                        showDialog(getString(R.string.Attention),
                                getString(R.string.NotExecutingAnyWO), new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        finish();
                                    }
                                });
                    } else if (!app.useLaborRecord()) {
                        Button btnInitEndWorkOrder = (Button) findViewById(R.id.BtnActionBar);

                        btnInitEndWorkOrder
                                .setText(getString(R.string.ChangeState));
                        btnInitEndWorkOrder
                                .setOnClickListener(new BtnChangeStateOnClick(
                                        WorkOrderInfo.this));

                        loadWorkOrderFields(workOrder);
                    } else
                        loadWorkOrderFields(workOrder);
                }

                /*if(progress.isShowing())
            progress.dismiss();*/
            } catch (InterruptedException e) {

                /*if(progress.isShowing())
            progress.dismiss();*/

                showDialog(getString(R.string.Error),
                        getString(R.string.LoadWOInfoError));
            }
        } else if (result == 0) {
            /*if(progress.isShowing())
            progress.dismiss();*/

            showDialog(getString(R.string.Error),
                    getString(R.string.LoadWOInfoError));
        }

        /*if(progress.isShowing())
            progress.dismiss();*/
    }
}

logcat的:

 FATAL EXCEPTION: AsyncTask #1
                                               Process: com.sisteplantbrasil, PID: 21888
                                               java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                   at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                   at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                   at java.lang.Thread.run(Thread.java:818)
                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference
                                                   at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
                                                   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                                                   at com.sisteplantbrasil.queries.sql.DBEntity.open(DBEntity.java:35)
                                                   at com.sisteplantbrasil.queries.sql.CompanyDBQueries.getCompanyParameterValue(CompanyDBQueries.java:214)
                                                   at com.sisteplantbrasil.WorkOrderInfo$LoadWorkOrderInfo.doInBackground(WorkOrderInfo.java:246)
                                                   at com.sisteplantbrasil.WorkOrderInfo$LoadWorkOrderInfo.doInBackground(WorkOrderInfo.java:222)
                                                   at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                   at java.lang.Thread.run(Thread.java:818) 

任何人都可以帮助我吗?感谢

0 个答案:

没有答案