0

我对 android 的 AIDL 文件有疑问。我从互联网上下载了一个示例项目,我在代码中看到,他们有一个 AIDL 文件。我不知道这个文件是什么,我做了一些研究并编写了一些代码。

创建 AIDL 文件后,我声明了一个这样的方法

interface IRemoteService{
  Map onClick(in int id, in Map state);
}

然后 Eclipse 将自动生成一个文件IRemoteService.java并返回错误:

cl cannot be resolved to a variable

我做错什么了吗?

编辑 这是自动生成的 IRemoteService.java。

/*
 * This file is auto-generated.  DO NOT MODIFY.
 * Original file: /home/nampham/Data/works/workspace/MapAidl/src/nampham/mapaidl/IRemoteService.aidl
 */
package nampham.mapaidl;
public interface IRemoteService extends android.os.IInterface
{
/** Local-side IPC implementation stub class. */
public static abstract class Stub extends android.os.Binder implements nampham.mapaidl.IRemoteService
{
private static final java.lang.String DESCRIPTOR = "nampham.mapaidl.IRemoteService";
/** Construct the stub at attach it to the interface. */
public Stub()
{
this.attachInterface(this, DESCRIPTOR);
}
/**
 * Cast an IBinder object into an nampham.mapaidl.IRemoteService interface,
 * generating a proxy if needed.
 */
public static nampham.mapaidl.IRemoteService asInterface(android.os.IBinder obj)
{
if ((obj==null)) {
return null;
}
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
if (((iin!=null)&&(iin instanceof nampham.mapaidl.IRemoteService))) {
return ((nampham.mapaidl.IRemoteService)iin);
}
return new nampham.mapaidl.IRemoteService.Stub.Proxy(obj);
}
public android.os.IBinder asBinder()
{
return this;
}
@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
{
switch (code)
{
case INTERFACE_TRANSACTION:
{
reply.writeString(DESCRIPTOR);
return true;
}
case TRANSACTION_click:
{
data.enforceInterface(DESCRIPTOR);
int _arg0;
_arg0 = data.readInt();
java.util.Map _arg1;
java.lang.ClassLoader cl = (java.lang.ClassLoader)this.getClass().getClassLoader();
_arg1 = data.readHashMap(cl);
java.util.Map _result = this.click(_arg0, _arg1);
reply.writeNoException();
reply.writeMap(_result);
return true;
}
}
return super.onTransact(code, data, reply, flags);
}
private static class Proxy implements nampham.mapaidl.IRemoteService
{
private android.os.IBinder mRemote;
Proxy(android.os.IBinder remote)
{
mRemote = remote;
}
public android.os.IBinder asBinder()
{
return mRemote;
}
public java.lang.String getInterfaceDescriptor()
{
return DESCRIPTOR;
}
public java.util.Map click(int id, java.util.Map state) throws android.os.RemoteException
{
android.os.Parcel _data = android.os.Parcel.obtain();
android.os.Parcel _reply = android.os.Parcel.obtain();
java.util.Map _result;
try {
_data.writeInterfaceToken(DESCRIPTOR);
_data.writeInt(id);
_data.writeMap(state);
mRemote.transact(Stub.TRANSACTION_click, _data, _reply, 0);
_reply.readException();
_result = _reply.readHashMap(cl);  `<<< This line return error`
}
finally {
_reply.recycle();
_data.recycle();
}
return _result;
}
}
static final int TRANSACTION_click = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
}
public java.util.Map click(int id, java.util.Map state) throws android.os.RemoteException;
}

提前致谢。

4

1 回答 1

0

问题出在:

_result = _reply.readHashMap(cl);

其中cl can't be resolved to a variable因为cl本地定义onTransact()

java.lang.ClassLoader cl = (java.lang.ClassLoader)this.getClass().getClassLoader();

我不知道是否auto-generated code意味着它不应该被修改它不能被修改。但是,我可以告诉您的是,除非您编辑了代码并且:

  • cl在错误行之前添加另一个定义:

    java.lang.ClassLoader cl = (java.lang.ClassLoader)this.getClass().getClassLoader();
    _result = _reply.readHashMap(cl);
    
于 2012-08-31T10:13:46.540 回答