プロジェクトにクラスを実装しようとしています...しかしonClick
、ボタンが押されたときにインテントを呼び出した後、エラーが発生します。あなたが私を助けることができるかどうかを確認するためのコードのスニペットを次に示します。
ファイル名:
QrCapture.java
qrcapture.xml
私のアンドロイドマニフェストには次のものがあります:
<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
乾杯!