无法实例接收抛出java.lang.ClassNotFoundException [英] Unable to instantiate receiver java.lang.ClassNotFoundException

查看:321
本文介绍了无法实例接收抛出java.lang.ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序出错时,它尝试实例,我用它来启动时自动打开一个服务的接收器。该错误是显而易见的,它无法找到我的接收器的类文件。但一切都确定了我的清单文件,包和一切,我不知道发生了什么。这是我的code:

I got an error in my android application when it tries to instantiate a receiver that i use to start a service on boot up. The error is obvious, it can not find the class file of my receiver. But everything is ok with my manifest file, the packages and all and i have no clue what is happening. Here is my code:

package dti.obd.reader;

import dti.obd.reader.service.MainService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootReceiver extends BroadcastReceiver 
{
      @Override
      public void onReceive(Context context, Intent intent) 
      {
            Intent serviceIntent = new Intent(MainService.class.getName());
            context.startService(serviceIntent);
      }
}

和我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dti.obd.reader"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <service android:name=".service.MainService" >
            <intent-filter >
                <action android:name="dti.obd.reader.service.MainService" />
            </intent-filter>
        </service>

        <receiver android:name="dti.obd.reader.BootReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED" >
                </action>
            </intent-filter>
        </receiver>
    </application>

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

</manifest>

有谁知道的埃罗?看来,包装和名称都OK了...

Does anyone knows the erro? It seems that the package and the names are all ok...

推荐答案

你必须把你的 Reciever 在某些。系统将不能够实例化,如果它是在主包装

You have to put your Reciever in some package. The system won't be able to instantiate if it is on the main package.

我有同样的问题。幸运的是在互联网上搜索错误之前我在做另一个Java项目。我才意识到,在那里的错误是与此类似。试了一下刚才和工作。 :)

I had the same problem. Fortunately before searching the error on internet I was doing another java project. I just realized that the bug in there was similar to this one. Tried it just now and worked. :)

这篇关于无法实例接收抛出java.lang.ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆