Java 尝试返回自定义类对象时发生AIDL错误
我试图在AIDL中使用IPC传递“响应”类对象。我已将课程包裹起来:Java 尝试返回自定义类对象时发生AIDL错误,java,android,service,android-studio,aidl,Java,Android,Service,Android Studio,Aidl,我试图在AIDL中使用IPC传递“响应”类对象。我已将课程包裹起来: public class Response implements Parcelable{ private long id; private String speechString; private List<String> responseString = new ArrayList<String>(); //set ... } //get
public class Response implements Parcelable{
private long id;
private String speechString;
private List<String> responseString = new ArrayList<String>();
//set
...
}
//get
...
public Response(Parcel in) {
id = in.readLong();
speechString = in.readString();
if (in.readByte() == 0x01) {
responseString = new ArrayList<String>();
in.readList(responseString, String.class.getClassLoader());
} else {
responseString = null;
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(speechString);
if (responseString == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(responseString);
}
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Response createFromParcel(Parcel in) {
return new Response(in);
}
public Response[] newArray(int size) {
return new Response[size];
}
};
}
IappMain.aidl用于IPC,定义如下:
package com.example;
// Declare any non-default types here with import statements
import com.example.Response;
interface IOizuuMain {
int app(String aString);
Response getResponseByString(String string);
}
但是在构建项目时,它在IappMain.java中给出了以下错误:
“错误:不兼容的类型:无法将对象转换为响应”位于此行:
_result = com.example.Response.CREATOR.createFromParcel(_reply);
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
尝试添加
公众回应(
{}
以上代码与下面提到的代码相同
public Response(Parcel in) { .....
。。。。
}
所以看起来应该是这样的
public Response(){}
公众回应(包裹内){。。。。。
....
}错误是由以下行引起的:
_result = com.example.Response.CREATOR.createFromParcel(_reply);
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
需要将类型参数添加到返回类型和正在创建的对象中。添加类型参数的更改如下:
public static final Parcelable.Creator<Response> CREATOR =
new Parcelable.Creator<Response>() {
公共静态最终包裹。创建者=
新建Parcelable.Creator(){
你真的需要AIDL吗?我的意思是,你真的需要远程服务吗?是的,因为我需要为我的应用程序提供插件开发支持。这与远程服务有什么关系?插件作为远程服务安装。中的对于AIDL中的字符串参数不是必需的(不确定它是否对您的问题有任何影响)