ClassNotFoundException / RuntimeException

时间:2012-04-25 16:16:10

标签: android android-activity android-intent

我正在尝试在我的项目中实现一个类...但是当按下按钮时调用intent 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

干杯!

3 个答案:

答案 0 :(得分:0)

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

实现onNewIntent,看看......可能会有所帮助

看起来像

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

if(action.equals("UR ACTION NAME")
{
  // do ur stuff here
}
}

答案 1 :(得分:0)

您可以尝试启动这样的意图:

Intent intent = new Intent(FirstActivity.this, QrCapture.class);
startActivity(intent);

答案 2 :(得分:0)

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

<activity android:name="org.jujitsu.app.com.QrCapture"