J_rad
J_rad

Reputation: 181

Android emulator can't find my Java class?

I have started building an android app that uses the ZXing library to read barcodes. The app I am developing uses a standalone barcode scanner- it doesn't use the android Intent object to scan a barcode. I have included the "core.jar" file in my project and have created a java class that scans a bitmap. To do this I have had to use include another class called RGBLuminanceSource- that I found on the java2s.com website. This class can read android bitmaps and is used to help create a LuminanceSource object because android can't use the AWT "BufferedImage" class to create "LuminaceSource" objects. My project compiles and builds without any errors, but when I try to run the project on the emulator (avd android version 1.5) I get the dreaded "the application "x" has stopped working unexpectedly.Please try again" message! I have looked through the DDMS logs and the only thing I can understand is that the emulator can't find the "RGBLuminanceSource" class that I added to the project. This causes problems because in order to decode the bitmap I have to make an object from the RGBLuminaceSource class.

I don't know why this is happening especially when the project builds without any problems, I am quite new to android programming so any help would be much appreciated, thank you.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.me.testgui;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.common.HybridBinarizer;
import java.io.FileInputStream;
import java.io.InputStream;


/**
 *
 * @author Gerrard
 */
public class TestClass
{
    protected static String scannedBarcode=null;
    private static InputStream is;


    protected static String testMethod()
    {
       String st = "THIS IS A TEST!!!!!!!!!!!";
       return st;
    }



    public static void readBarcode(String file) throws NotFoundException
    {


        try
        {
            //file = "D:\\NetBeansProjects\\TestGUI\\res\\drawable\\barcode1.jpg";
            is = new FileInputStream(file);



            // Create a BitMap object of the image to be worked with
            Bitmap bm = BitmapFactory.decodeStream(is);//create a bitmap from the imput stream "is" object
            RGBLuminanceSource rgbSource = new RGBLuminanceSource(bm);//create an object type RGBLuminanceSource so that the android type bitmap can be read by the ZXing LumincaceSource class
            System.out.println("RGBLuminance object created");

           LuminanceSource source = rgbSource;




            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            Reader reader = new MultiFormatReader();

            com.google.zxing.Result result = reader.decode(bitmap);



            String barcode = String.format("Barcode text is: " + result.getText());
           scannedBarcode = barcode;


        }
        catch(Exception e)
        {
            //Toast.makeText(MainActivity,"ERROR: " +e.toString(), Toast.LENGTH_SHORT).show();
        }



    }
}

I have also included the DDMS logs to help track down the source of the problem

 10-12 20:27:07.126: DEBUG/AndroidRuntime(833): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<


    10-12 20:27:07.149: DEBUG/AndroidRuntime(833): CheckJNI is ON
    10-12 20:27:08.966: DEBUG/AndroidRuntime(833): --- registering native functions ---
    10-12 20:27:09.038: INFO/jdwp(833): received file descriptor 22 from ADB
    10-12 20:27:10.086: INFO/jdwp(833): Ignoring second debugger -- accepting and dropping
    10-12 20:27:12.115: DEBUG/AndroidRuntime(833): Shutting down VM
    10-12 20:27:12.135: DEBUG/dalvikvm(833): DestroyJavaVM waiting for non-daemon threads to exit
    10-12 20:27:12.175: DEBUG/dalvikvm(833): DestroyJavaVM shutting VM down
    10-12 20:27:12.185: DEBUG/dalvikvm(833): HeapWorker thread shutting down
    10-12 20:27:12.195: DEBUG/dalvikvm(833): HeapWorker thread has shut down
    10-12 20:27:12.206: DEBUG/jdwp(833): JDWP shutting down net...
    10-12 20:27:12.229: DEBUG/jdwp(833): +++ peer disconnected
    10-12 20:27:12.235: INFO/dalvikvm(833): Debugger has detached; object registry had 1 entries
    10-12 20:27:12.376: DEBUG/dalvikvm(833): VM cleaning up
    10-12 20:27:12.475: DEBUG/dalvikvm(833): LinearAlloc 0x0 used 629804 of 4194304 (15%)
    10-12 20:27:13.345: DEBUG/AndroidRuntime(843): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    10-12 20:27:13.356: DEBUG/AndroidRuntime(843): CheckJNI is ON
    10-12 20:27:13.902: DEBUG/AndroidRuntime(843): --- registering native functions ---
    10-12 20:27:13.955: INFO/jdwp(843): received file descriptor 22 from ADB
    10-12 20:27:13.955: INFO/jdwp(843): Ignoring second debugger -- accepting and dropping
    10-12 20:27:16.821: DEBUG/PackageParser(554): Scanning package: /data/app/vmdl33973.tmp
    10-12 20:27:17.546: INFO/PackageManager(554): Removing non-system package:org.me.testgui
    10-12 20:27:17.595: DEBUG/PackageManager(554): Removing package org.me.testgui
    10-12 20:27:17.625: DEBUG/PackageManager(554):   Activities: org.me.testgui.MainActivity
    10-12 20:27:18.067: DEBUG/PackageManager(554): Scanning package org.me.testgui
    10-12 20:27:18.107: INFO/PackageManager(554): /data/app/vmdl33973.tmp changed; unpacking
    10-12 20:27:18.185: DEBUG/installd(559): DexInv: --- BEGIN '/data/app/vmdl33973.tmp' ---
    10-12 20:27:19.125: DEBUG/dalvikvm(849): DexOpt: load 155ms, verify 235ms, opt 2ms
    10-12 20:27:19.195: DEBUG/installd(559): DexInv: --- END '/data/app/vmdl33973.tmp' (success) ---
    10-12 20:27:19.205: DEBUG/PackageManager(554):   Activities: org.me.testgui.MainActivity
    10-12 20:27:19.375: INFO/installd(559): move /data/dalvik-cache/data@[email protected]@classes.dex -> /data/dalvik-cache/data@[email protected]@classes.dex
    10-12 20:27:19.417: DEBUG/PackageManager(554): New package installed in /data/app/org.me.testgui.apk
    10-12 20:27:19.705: DEBUG/AndroidRuntime(843): Shutting down VM
    10-12 20:27:19.715: DEBUG/dalvikvm(843): DestroyJavaVM waiting for non-daemon threads to exit
    10-12 20:27:19.785: DEBUG/ActivityManager(554): Uninstalling process org.me.testgui
    10-12 20:27:19.805: DEBUG/dalvikvm(843): DestroyJavaVM shutting VM down
    10-12 20:27:19.805: DEBUG/dalvikvm(843): HeapWorker thread shutting down
    10-12 20:27:19.815: DEBUG/dalvikvm(843): HeapWorker thread has shut down
    10-12 20:27:19.815: DEBUG/jdwp(843): JDWP shutting down net...
    10-12 20:27:19.815: DEBUG/jdwp(843): +++ peer disconnected
    10-12 20:27:19.815: INFO/dalvikvm(843): Debugger has detached; object registry had 1 entries
    10-12 20:27:19.825: DEBUG/dalvikvm(843): VM cleaning up
    10-12 20:27:19.935: DEBUG/dalvikvm(843): LinearAlloc 0x0 used 629572 of 4194304 (15%)
    10-12 20:27:20.497: WARN/ResourceType(554): No package identifier when getting value for resource number 0x7f060000
    10-12 20:27:20.538: WARN/ResourceType(554): No package identifier when getting value for resource number 0x7f060001
    10-12 20:27:20.585: DEBUG/HomeLoaders(620): application intent received: android.intent.action.PACKAGE_REMOVED, replacing=true
    10-12 20:27:20.615: DEBUG/HomeLoaders(620):   --> package:org.me.testgui
    10-12 20:27:20.635: DEBUG/HomeLoaders(620): application intent received: android.intent.action.PACKAGE_ADDED, replacing=true
    10-12 20:27:20.655: DEBUG/HomeLoaders(620):   --> package:org.me.testgui
    10-12 20:27:20.665: DEBUG/HomeLoaders(620):   --> update package org.me.testgui
    10-12 20:27:20.876: DEBUG/dalvikvm(554): GC freed 9144 objects / 423280 bytes in 323ms
    10-12 20:27:21.315: WARN/ResourceType(554): No package identifier when getting value for resource number 0x7f060000
    10-12 20:27:21.366: WARN/ResourceType(554): No package identifier when getting value for resource number 0x7f060001
    10-12 20:27:22.840: DEBUG/AndroidRuntime(854): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    10-12 20:27:22.845: DEBUG/AndroidRuntime(854): CheckJNI is ON
    10-12 20:27:23.786: DEBUG/AndroidRuntime(854): --- registering native functions ---
    10-12 20:27:23.795: INFO/jdwp(854): received file descriptor 22 from ADB
    10-12 20:27:23.829: INFO/jdwp(854): Ignoring second debugger -- accepting and dropping
    10-12 20:27:25.965: INFO/ActivityManager(554): Starting activity: Intent { flags=0x10000000 comp={org.me.testgui/org.me.testgui.MainActivity} }
    10-12 20:27:26.876: DEBUG/AndroidRuntime(854): Shutting down VM
    10-12 20:27:26.886: DEBUG/dalvikvm(854): DestroyJavaVM waiting for non-daemon threads to exit
    10-12 20:27:26.936: DEBUG/dalvikvm(854): DestroyJavaVM shutting VM down
    10-12 20:27:26.947: DEBUG/dalvikvm(854): HeapWorker thread shutting down
    10-12 20:27:26.947: DEBUG/dalvikvm(854): HeapWorker thread has shut down
    10-12 20:27:26.947: DEBUG/jdwp(854): JDWP shutting down net...
    10-12 20:27:26.976: DEBUG/jdwp(854): +++ peer disconnected
    10-12 20:27:26.976: INFO/dalvikvm(854): Debugger has detached; object registry had 1 entries
    10-12 20:27:26.986: DEBUG/dalvikvm(854): VM cleaning up
    10-12 20:27:27.046: DEBUG/dalvikvm(854): LinearAlloc 0x0 used 639228 of 4194304 (15%)
    10-12 20:27:27.286: INFO/ActivityManager(554): Start proc org.me.testgui for activity org.me.testgui/.MainActivity: pid=862 uid=10024 gids={1006}
    10-12 20:27:27.809: INFO/jdwp(862): received file descriptor 10 from ADB
    10-12 20:27:28.055: INFO/jdwp(862): Ignoring second debugger -- accepting and dropping
    10-12 20:27:28.105: WARN/System.err(862): Can't dispatch DDM chunk 46454154: no handler defined
    10-12 20:27:28.146: WARN/System.err(862): Can't dispatch DDM chunk 4d505251: no handler defined
    10-12 20:27:29.375: WARN/Resources(862): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f050001}
    10-12 20:27:29.915: WARN/dalvikvm(862): Unable to resolve superclass of Lorg/me/testgui/RGBLuminanceSource; (30)
    10-12 20:27:29.925: WARN/dalvikvm(862): Link of class 'Lorg/me/testgui/RGBLuminanceSource;' failed
    10-12 20:27:29.925: ERROR/dalvikvm(862): Could not find class 'org.me.testgui.RGBLuminanceSource', referenced from method org.me.testgui.TestClass.readBarcode
    10-12 20:27:29.936: WARN/dalvikvm(862): VFY: unable to resolve new-instance 68 (Lorg/me/testgui/RGBLuminanceSource;) in Lorg/me/testgui/TestClass;
    10-12 20:27:29.936: WARN/dalvikvm(862): VFY:  rejecting opcode 0x22 at 0x000d
    10-12 20:27:29.936: WARN/dalvikvm(862): VFY:  rejected Lorg/me/testgui/TestClass;.readBarcode (Ljava/lang/String;)V
    10-12 20:27:29.955: WARN/dalvikvm(862): Verifier rejected class Lorg/me/testgui/TestClass;
    10-12 20:27:29.975: DEBUG/AndroidRuntime(862): Shutting down VM
    10-12 20:27:29.985: WARN/dalvikvm(862): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
    10-12 20:27:29.985: ERROR/AndroidRuntime(862): Uncaught handler: thread main exiting due to uncaught exception
    10-12 20:27:30.075: ERROR/AndroidRuntime(862): java.lang.VerifyError: org.me.testgui.TestClass
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at org.me.testgui.MainActivity.onCreate(MainActivity.java:182)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.os.Handler.dispatchMessage(Handler.java:99)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.os.Looper.loop(Looper.java:123)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at android.app.ActivityThread.main(ActivityThread.java:3948)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at java.lang.reflect.Method.invokeNative(Native Method)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at java.lang.reflect.Method.invoke(Method.java:521)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
    10-12 20:27:30.075: ERROR/AndroidRuntime(862):     at dalvik.system.NativeStart.main(Native Method)
    10-12 20:27:30.105: INFO/Process(554): Sending signal. PID: 862 SIG: 3
    10-12 20:27:30.105: INFO/dalvikvm(862): threadid=7: reacting to signal 3
    10-12 20:27:30.356: INFO/dalvikvm(862): Wrote stack trace to '/data/anr/traces.txt

Upvotes: 1

Views: 2535

Answers (2)

Sean Owen
Sean Owen

Reputation: 66886

To answer the question and others raised:

  • RGBLuminanceSource is in zxing under androidtest/
  • If you didn't set the package properly in your copy, it would not have compiled
  • VerifyError means it didn't like the bytecode. Sometimes, using Proguard causes this. If you want to do that, use the Proguard optimizaiton built into Android. But that's probably not the case here.
  • It's probably that you have not put core.jar into your project quite right. Usually you just leave it in libs/ and it works.
  • (Don't forget to pay attention to the Apache License 2.0 terms if you use our code in your app.)

Upvotes: 2

Caner
Caner

Reputation: 59168

VerifyError means that the class file contains bytecode that is syntactically correct but violates some semantic restriction e.g. a jump target that crosses method boundaries.

.

java.lang.VerifyError can be the result when you have compiled against a different library than you are using at runtime.

EDIT:
.

Check this for more info:

Causes of getting a java.lang.VerifyError

EDIT2:
ok, according to what you say, I guess you did not properly set the package of RGBLuminanceSource file. Since you copied this file into your project it should be in your package.

So change this:

package com.google.zxing.client.androidtest;

To this:

package org.me.correct.package;

Upvotes: 0

Related Questions