首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClassNotFoundException / RuntimeException

ClassNotFoundException / RuntimeException
EN

Stack Overflow用户
提问于 2012-04-25 16:16:09
回答 3查看 232关注 0票数 0

我正试图在我的项目中实现一个类.然而,当按下按钮后,它会给我一个错误。这是我的代码片段,看看你能不能帮我。

文件名:

QrCapture.java

qrcapture.xml

在我的android宣言中,我有:

代码语言:javascript
复制
    <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文件中有:

代码语言:javascript
复制
<?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文件包含以下源代码:

代码语言:javascript
复制
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);
}

}

我以这样的方式开始这项活动:

代码语言:javascript
复制
 Intent i = new Intent("org.jujitsu.app.qrcapture");
 startActivity(i);

下面是我所犯的错误:

代码语言:javascript
复制
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

干杯!

EN

回答 3

Stack Overflow用户

发布于 2012-04-25 16:23:55

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

以这样的方式实现onNewIntent并参见..。也许这能帮上忙

看起来就像

代码语言:javascript
复制
public void onNewIntent(Intent intent)
{
  String action = intent.getAction();

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

Stack Overflow用户

发布于 2012-04-25 16:24:40

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

代码语言:javascript
复制
Intent intent = new Intent(FirstActivity.this, QrCapture.class);
startActivity(intent);
票数 0
EN

Stack Overflow用户

发布于 2012-04-25 16:38:24

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

代码语言:javascript
复制
<activity android:name="org.jujitsu.app.com.QrCapture" 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10319641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档