0

我正在尝试在我的项目中实现一个类......但是在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

干杯!

4

3 回答 3

0

尝试将完整的包名放在清单中

<activity android:name="org.jujitsu.app.com.QrCapture" 
于 2012-04-25T16:38:24.753 回答
0

您如何处理活动 QrCapture 中的操作?

像这样实施 onNewIntent 并查看...可能会有所帮助

它看起来像

public void onNewIntent(Intent intent)
{
  String action = intent.getAction();

if(action.equals("UR ACTION NAME")
{
  // do ur stuff here
}
}
于 2012-04-25T16:23:55.897 回答
0

您可以尝试像这样开始意图:

Intent intent = new Intent(FirstActivity.this, QrCapture.class);
startActivity(intent);
于 2012-04-25T16:24:40.857 回答