0

I have a Activity that calls another Activity (Draw) with startActivityForResult, but when i finish the another Activity the app crash before enter in onActivityResult (First Activity), with RuntimeException.

This is the way how i call my Draw Activity:

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());

in the new Activity:

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

AsyncTask (I not using this async task in this time, but it is the asynctask mentionated in logcat):

public class LoadWorkOrderInfo extends 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) 

Anyone can help me? Thanks

Flavio Luiz
  • 37
  • 1
  • 7

0 Answers0