0

I am trying to follow the sample of the barcode reader from codelabs. However I am stuck, could someone help me out please.
Codelabs tutorial

I have updated the manifests to include the vision libaries.

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;

//stop here

public class barcode  extends Activity {
TextView txtView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_barcode);
        ImageView myImageView = (ImageView) findViewById(R.id.imgview);
        Bitmap myBitmap = BitmapFactory.decodeResource(
                getApplicationContext().getResources(),
                R.drawable.puppy);
        myImageView.setImageBitmap(myBitmap);

        Button btn = (Button) findViewById(R.id.button);

        btn.setOnClickListener(new View.OnClickListener() {
                @Override

            public void onClick(View v) {
            txtView = (TextView)findViewById(R.id.txtContent);
            txtView.setText("It works");

                }//end of on click

        });
        BarcodeDetector detector =
                new BarcodeDetector.Builder(getApplicationContext())
                        .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
                        .build();
        if(!detector.isOperational()){
            txtView.setText("Could not set up the detector!");
            return;
        }

    }

}
3
Contributors
4
Replies
18
Views
1 Week
Discussion Span
Last Post by rproffitt
0

You could at least have mentioned what it is you're stuck with.

Did you add code yourself, or just copy-pasted from that tutorial? What do you expect the (current) code to do? Does it compile? Does it run?

If you get exceptions, are they compile- or runtime? Can you show us a StackTrace?

If it runs, does it give the result you expect? If not, what does it do, and what part is supposed to be different?

0

The App crashes when ever I hit the button. My applogies I got obsessed when trying to get this to run.

The app is supposed to load the saved qr code (saved as png).
Process and decode said qr
the output the contents of the qr code to the textview.

The image loads correctly but when the button is pressed the app crashes

0

define "the app crashes".

does it 'hang'? do you get an error message? do you get a stacktrace? have you checked your logs?

0

Small world. I'm on a team working on Android Apps using ... Android Studio. One of the best things about Android Studio (AS) to me is that when I run it from AS over the USB link, when it crashes I get to see what line it crashed on and can see what variables and more are at the time of crash.

We're all new at some point so my feedback is to run your app over USB or if possible the emulator so you can trace back to what caused the crash.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.