我的应用程序模块正在同一个项目中为各种类使用库模块。 Android Studio中没有显示错误,当我构建时,我没有任何错误。但是当它试图从库中访问我的一个类时,它会抛出一个NoClassDef异常。有谁知道我做错了什么? Logcat输出如下。
服务清单(我使用自定义SDK):
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.linear.deviceservice"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19"
tools:ignore="OldTargetApi" />
<uses-permission android:name="android.permission.SERIAL_PORT"/>
<application
android:allowBackup="true">
<service
android:name="LinearService"
android:exported="true"
android:permission="com.project.permission.DEVICE_SERVICE">
<intent-filter>
<action android:name="com.project.deviceservice.BIND"/>
</intent-filter>
</service>
</application>
</manifest>
在我的主要申请中:
List<PeripheralDevice> devices =
mConfigurationManager.getConfiguration().getPeripheralDevices();
/* Send the update message with list of appropriate uris to each service. */
ArrayList<Uri> uris;
/* For each service, get the list of uris for that service. */
for (String scheme : mServices.keySet()) {
uris = new ArrayList<Uri>();
for (PeripheralDevice device : devices) {
if (scheme.equals(device.getUri().getScheme())) {
uris.add(device.getUri());
}
}
/* Send the update message here. */
updateDevices(mServices.get(scheme), uris);
}
在我的服务中:
protected List<IDevice> mDevices = new ArrayList<IDevice>();
...
{
mDevices = msg.getData().getParcelableArrayList(Messages.DEVICES_KEY);
}
logcat的
12-11 12:24:45.717 2391-2406/com.linear.service E/Parcel: Class not found when unmarshalling: com.project.deviceservice.Device
java.lang.ClassNotFoundException: com.project.deviceservice.Device
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
at android.os.Parcel.readParcelable(Parcel.java:2097)
at android.os.Parcel.readValue(Parcel.java:2013)
at android.os.Parcel.readListInternal(Parcel.java:2343)
at android.os.Parcel.readArrayList(Parcel.java:1703)
at android.os.Parcel.readValue(Parcel.java:2034)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getParcelableArrayList(Bundle.java:1250)
at com.project.deviceservice.DeviceService$1.handleMessage(DeviceService.java:50)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.NoClassDefFoundError: com/project/deviceservice/Device
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
at android.os.Parcel.readParcelable(Parcel.java:2097)
at android.os.Parcel.readValue(Parcel.java:2013)
at android.os.Parcel.readListInternal(Parcel.java:2343)
at android.os.Parcel.readArrayList(Parcel.java:1703)
at android.os.Parcel.readValue(Parcel.java:2034)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getParcelableArrayList(Bundle.java:1250)
at com.project.deviceservice.DeviceService$1.handleMessage(DeviceService.java:50)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.project.deviceservice.Device" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at android.os.Parcel.readParcelableCreator(Parcel.java:2133)
at android.os.Parcel.readParcelable(Parcel.java:2097)
at android.os.Parcel.readValue(Parcel.java:2013)
at android.os.Parcel.readListInternal(Parcel.java:2343)
at android.os.Parcel.readArrayList(Parcel.java:1703)
at android.os.Parcel.readValue(Parcel.java:2034)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getParcelableArrayList(Bundle.java:1250)
at com.project.deviceservice.DeviceService$1.handleMessage(DeviceService.java:50)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
12-11 12:24:45.727 2391-2406/com.linear.service W/dalvikvm: threadid=11: thread exiting with uncaught exception (group=0x41c21ba8)
12-11 12:24:45.727 2391-2406/com.linear.service E/AndroidRuntime: FATAL EXCEPTION: LinearService Messenger
Process: com.linear.service, PID: 2391
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.project.deviceservice.Device
at android.os.Parcel.readParcelableCreator(Parcel.java:2147)
at android.os.Parcel.readParcelable(Parcel.java:2097)
at android.os.Parcel.readValue(Parcel.java:2013)
at android.os.Parcel.readListInternal(Parcel.java:2343)
at android.os.Parcel.readArrayList(Parcel.java:1703)
at android.os.Parcel.readValue(Parcel.java:2034)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
at android.os.Bundle.unparcel(Bundle.java:249)
at android.os.Bundle.getParcelableArrayList(Bundle.java:1250)
at com.project.deviceservice.DeviceService$1.handleMessage(DeviceService.java:50)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
答案 0 :(得分:0)
问题通过添加:
解决Bundle data = msg.getData();
data.setClassLoader(IDevice.class.getClassLoader());