Android“cl无法解析为变量”错误

时间:2012-08-31 02:54:24

标签: android

我的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;
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

问题在于:

_result = _reply.readHashMap(cl);

cl can't be resolved to a variable clonTransact() 在本地定义 <{1}}:

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);