Android Intent导致NoClassDefFoundError

时间:2012-07-16 01:21:41

标签: android android-intent noclassdeffounderror

我在尝试创建新的Intent以启动服务时遇到了NoClassDefFoundError。我检查了几个建议的解决方案,比如在/ libs路径中包含库,我相信我已经正确设置了这些。我在下面列出了我的清单和来源。任何帮助都会非常感激。

这是我在Eclipse中的文件结构的屏幕截图 enter image description here

这是我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ajinex.easysave"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".CouponsActivity"
        android:screenOrientation="portrait"
        android:launchMode="singleInstance"
        android:label="@string/title_activity_coupons" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
        <!--  service  -->
        <service android:enabled="true" android:name=".LocationCheckService" >
    </service>
</application>

这是我在MainActivity中的调用代码:

Intent LocationCheck = new Intent(this, LocationCheckService.class);
    this.startService(LocationCheck);    

这是我的LocationCheckService.class

public class LocationCheckService extends Service {
    public class LocalBinder extends Binder {
        LocationCheckService getService() {
            return LocationCheckService.this;
        }
    }


    public final IBinder mBinder = new LocalBinder();

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if(checkNetworkRechability()){
            Toast.makeText(this, "EasySave Service Started", Toast.LENGTH_LONG).show();
            getSysLocation();
        }
        return START_STICKY;
    }
    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {

    }
}    

以下是与此问题相关的一些LogCat输出:

07-16 00:09:36.712: I/AndroidRuntime(312): NOTE: attach of thread 'Binder Thread #3' failed
07-16 00:09:37.702: W/ActivityManager(59): Unable to start service Intent { act=com.ajinex.easysave.location.LocationCheckService }: not found
07-16 00:09:38.162: I/ActivityManager(59): Displayed activity   com.ajinex.easysave/.MainActivity: 1568 ms (total 1568 ms)

2 个答案:

答案 0 :(得分:1)

尝试:

    Intent LocationCheck = new Intent();
    LocationCheck.setComponent(new ComponentName("com.ajinex.easysave", 
    "com.ajinex.easysave.LocationCheckService"));
    this.startService(LocationCheck);

答案 1 :(得分:1)

根据错误消息(com.ajinex.easysave.location.LocationCheckService)和包名称(com.ajinex.easysave),您需要在清单文件中将服务声明为.location.LocationCheckService。