lanjava.lang.runtimeexception:无法销毁活动{com.example.quickfinder / com.example.quickfinder.ocrresult}:java.lang.nullpointerexception

时间:2015-03-11 05:49:01

标签: java android ocr tesseract

package com.example.quickfinder;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Ocrresult extends Activity {

    private TessOCR mTessOCR;
    TextView txt1;
    Button save, cancel;
    ImageView viewImage;
    Bitmap bmp;
    private ProgressDialog mProgressDialog;
    private String mCurrentPhotoPath;

    private TextView mResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.nextactivity);
        mResult = (TextView)findViewById(R.id.textView1);
        mResult.setTextColor(Color.BLACK);
        save = (Button)findViewById(R.id.save);
        cancel= (Button)findViewById(R.id.cancel);

        ImageView view = (ImageView) findViewById(R.id.image); 

        byte[] byteArray = getIntent().getByteArrayExtra("image");
        bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        view.setImageBitmap(bmp);
        doOCR(bmp);
    }

    private void doOCR(final Bitmap bitmap) {
    if (mProgressDialog == null)
    {
        mProgressDialog = ProgressDialog.show(this, "Processing", "Doing OCR...", true);
    }
    else
    {
        mProgressDialog.show();
        //make comment hre from dialog box////////////////  
        new Thread(new Runnable() 
        {
            public void run() 
            {
                final String result = mTessOCR.getOCRResult(bitmap);
                runOnUiThread(new Runnable()
                {
                    @Override
                    public void run() 
                    {
                        // TODO Auto-generated method stub
                        if (result != null && !result.equals(""))
                        {
                            mResult.setText(result);
                        }
                        mProgressDialog.dismiss();
                    }
                });                   
            };
        }).start();
        ///////////complete coment hre for dialog.
    }


    ///////////////destroing avtivity after use compete//////////////////
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        mTessOCR.onDestroy();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }
}

当我运行此活动时,这是我的OCRresult活动的代码,它在logcat中返回此错误:

lanjava.lang.runtimeexception: unable to destroy activity {com.example.quickfinder/com.example.quickfinder.ocrresult}:java.lang.nullpointerexception" 

如何解决此问题?

0 个答案:

没有答案