Reputation: 441
I was reluctant to post this question after banging my head against my desk and carving though related post on stackoverflow, but just can't get the problem resolved. So here we are. I am trying integrate ZXing into my Android app as many developers have attempted but have consistently gotten the same error: Unable to start activity ComponentInfo
. I have core.jar added and have added the activity and camera permissions to the manifest. I know there is something very simple I am missing to do here. I get the following error when trying to scan using intent. I have already tried going through the ZXing library and changing all switch statements to if/else. I have also tried adding my package name in the ZXing layouts like suggested here: Android ZXing implementation
Java:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainMenu extends Activity {
Button btn_scan
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
btn_scan = (Button) findViewById(R.id.btn_scanbarcode);
btn_scan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Manifest
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
LogCat:
11-30 10:54:04.713: E/AndroidRuntime(15452): FATAL EXCEPTION: main
11-30 10:54:04.713: E/AndroidRuntime(15452): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.testapp/com.google.zxing.client.android.CaptureActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2240)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2275)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.os.Looper.loop(Looper.java:156)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread.main(ActivityThread.java:5060)
11-30 10:54:04.713: E/AndroidRuntime(15452): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 10:54:04.713: E/AndroidRuntime(15452): at java.lang.reflect.Method.invoke(Method.java:511)
11-30 10:54:04.713: E/AndroidRuntime(15452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-30 10:54:04.713: E/AndroidRuntime(15452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-30 10:54:04.713: E/AndroidRuntime(15452): at dalvik.system.NativeStart.main(Native Method)
11-30 10:54:04.713: E/AndroidRuntime(15452): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-30 10:54:04.713: E/AndroidRuntime(15452): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:278)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.Activity.setContentView(Activity.java:1897)
11-30 10:54:04.713: E/AndroidRuntime(15452): at com.google.zxing.client.android.CaptureActivity.onCreate(CaptureActivity.java:143)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.Activity.performCreate(Activity.java:4543)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2196)
11-30 10:54:04.713: E/AndroidRuntime(15452): ... 11 more
11-30 10:54:04.713: E/AndroidRuntime(15452): Caused by: java.lang.ClassNotFoundException: com.android.testapp
11-30 10:54:04.713: E/AndroidRuntime(15452): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-30 10:54:04.713: E/AndroidRuntime(15452): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-30 10:54:04.713: E/AndroidRuntime(15452): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-30 10:54:04.713: E/AndroidRuntime(15452): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
11-30 10:54:04.713: E/AndroidRuntime(15452): ... 21 more
Upvotes: 1
Views: 3116
Reputation: 66866
There are several problems here, among them that you are trying to declare our activity and namespace in your app. Please do not do this. It doesn't work for you and causes problems for our users.
You seem to want to do this: https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
If so it's way easier than you are making it here.
Upvotes: 1
Reputation: 441
You have import zxing project as a library and strip out classes you don't need. This process was painful but i got it working.
Upvotes: 1