我使用下面的代码创建了Zxing预定义的QR码阅读器,但我正在致命的例外。我还在我的项目libs文件夹中定义了core.java。有人可以帮我解决这个问题吗?
MainActivity
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
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;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener {
private Button scanBtn;
private TextView formatTxt, contentTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scanBtn = (Button)findViewById(R.id.scan_button);
formatTxt = (TextView)findViewById(R.id.scan_format);
contentTxt = (TextView)findViewById(R.id.scan_content);
scanBtn.setOnClickListener(this);
}
public void OnActivityResultListener(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK){
//we have a result
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
formatTxt.setText("FORMAT: " + contents);
contentTxt.setText("CONTENT: " + format);
}
else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Toast toast = Toast.makeText(this, "Scan was Cancelled!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 25, 400);
toast.show();
}
}
}
@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
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE,PRODUCT_MODE");
startActivityForResult(intent, 0);
/* if(v.getId()==R.id.scan_button){
//scan
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
} */
}
}
activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.qrcodereader.MainActivity" >
<Button android:id="@+id/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="scan" />
<TextView
android:id="@+id/scan_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/scan_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/scan_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="46dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
QRcodeReader Mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.qrcodereader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
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>
</application>
</manifest>
错误日志
01-03 13:42:20.931: E/AndroidRuntime(335): FATAL EXCEPTION: main
01-03 13:42:20.931: E/AndroidRuntime(335): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.example.qrcodereader
/com.google.zxing.client.android.CaptureActivity}: android.view.InflateException:
Binary XML file line #35: Error inflating class <unknown>
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-03 13:42:20.931: E/AndroidRuntime(335): at android.os.Looper.loop(Looper.java:123)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread.main(ActivityThread.java:3683)
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Method.invokeNative(Native Method)
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Method.invoke(Method.java:507)
01-03 13:42:20.931: E/AndroidRuntime(335): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-03 13:42:20.931: E/AndroidRuntime(335): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-03 13:42:20.931: E/AndroidRuntime(335):
at dalvik.system.NativeStart.main(Native Method)
01-03 13:42:20.931: E/AndroidRuntime(335): Caused by:
android.view.InflateException: Binary XML file line
#35: Error inflating class <unknown>
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createView(LayoutInflater.java:518)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-03 13:42:20.931: E/AndroidRuntime(335): at
com.android.internal.policy.impl.PhoneWindow.setContentView
(PhoneWindow.java:207)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.Activity.setContentView(Activity.java:1657)
01-03 13:42:20.931: E/AndroidRuntime(335): at
com.google.zxing.client.android.CaptureActivity.onCreate
(CaptureActivity.java:140)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1047)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
01-03 13:42:20.931: E/AndroidRuntime(335): ... 11 more
01-03 13:42:20.931: E/AndroidRuntime(335): Caused by:
java.lang.reflect.InvocationTargetException
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Constructor.constructNative(Native Method)
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Constructor.newInstance(Constructor.java:415)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createView(LayoutInflater.java:505)
01-03 13:42:20.931: E/AndroidRuntime(335): ... 23 more
01-03 13:42:20.931: E/AndroidRuntime(335): Caused by: android.view.InflateException:
Binary XML file line #17: Error inflating class <unknown>
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createView(LayoutInflater.java:518)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.inflate(LayoutInflater.java:386)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.support.v7.internal.widget.ActionBarView.<init>(ActionBarView.java:218)
01-03 13:42:20.931: E/AndroidRuntime(335): ... 26 more
01-03 13:42:20.931: E/AndroidRuntime(335): Caused by:
java.lang.reflect.InvocationTargetException
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Constructor.constructNative(Native Method)
01-03 13:42:20.931: E/AndroidRuntime(335): at
java.lang.reflect.Constructor.newInstance(Constructor.java:415)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.view.LayoutInflater.createView(LayoutInflater.java:505)
01-03 13:42:20.931: E/AndroidRuntime(335): ... 30 more
01-03 13:42:20.931: E/AndroidRuntime(335): Caused by:
android.content.res.Resources$NotFoundException:
Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010010 a=-1}
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.content.res.Resources.loadDrawable(Resources.java:1681)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-03 13:42:20.931: E/AndroidRuntime(335):
at android.view.View.<init>(View.java:1951)
01-03 13:42:20.931: E/AndroidRuntime(335):
at android.view.ViewGroup.<init>(ViewGroup.java:292)
01-03 13:42:20.931: E/AndroidRuntime(335): at android.widget.FrameLayout.<init>
(FrameLayout.java:88)
01-03 13:42:20.931: E/AndroidRuntime(335): at android.widget.FrameLayout.<init>
(FrameLayout.java:84)
01-03 13:42:20.931: E/AndroidRuntime(335): at
android.support.v7.internal.widget.ActionBarView$HomeView.<init>
(ActionBarView.java:1258)
01-03 13:42:20.931: E/AndroidRuntime(335): ... 33 more