我正在尝试在我的项目中实现一个类......但是在onClick
按下按钮时调用意图后它给了我一个错误。这是我的代码片段,看看您是否可以帮助我。
文件名:
QrCapture.java
qrcapture.xml
在我的 android 清单中,我有:
<activity android:name=".QrCapture"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<action android:name="org.jujitsu.app.qrcapture" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
在 qrcapture.xml 文件中,我有:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<FrameLayout
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center_horizontal">
<include layout="@layout/capture"/>
</FrameLayout>
</LinearLayout>
我的 qrcapture.java 文件包含以下源:
package org.jujitsu.app.com;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Toast;
public class QrCapture extends CaptureActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.qrcapture);
}
//TODO Save bitmap to file.
@Override
public void handleDecode(Result rawResult, Bitmap barcode)
{
Toast.makeText(this.getApplicationContext(), "Scanned code "+ rawResult.getText(), Toast.LENGTH_LONG);
}
}
我以这种方式开始活动:
Intent i = new Intent("org.jujitsu.app.qrcapture");
startActivity(i);
这是我得到的错误:
04-25 16:49:09.220: E/AndroidRuntime(1010): FATAL EXCEPTION: main
04-25 16:49:09.220: E/AndroidRuntime(1010): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.jujitsu.app.com/org.jujitsu.app.com.QrCapture}: java.lang.ClassNotFoundException: org.jujitsu.app.com.QrCapture
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2118)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread.access$600(ActivityThread.java:139)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.os.Looper.loop(Looper.java:154)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread.main(ActivityThread.java:4974)
04-25 16:49:09.220: E/AndroidRuntime(1010): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 16:49:09.220: E/AndroidRuntime(1010): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 16:49:09.220: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-25 16:49:09.220: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-25 16:49:09.220: E/AndroidRuntime(1010): at dalvik.system.NativeStart.main(Native Method)
04-25 16:49:09.220: E/AndroidRuntime(1010): Caused by: java.lang.ClassNotFoundException: org.jujitsu.app.com.QrCapture
04-25 16:49:09.220: E/AndroidRuntime(1010): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-25 16:49:09.220: E/AndroidRuntime(1010): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-25 16:49:09.220: E/AndroidRuntime(1010): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
04-25 16:49:09.220: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2109)
04-25 16:49:09.220: E/AndroidRuntime(1010): ... 11 more
干杯!