0

I have a problem with AIDL file of android. I downloaded a sample project from internet, I saw in the code, they have an AIDL file. I don't know what this file is and I do some research and write some code.

After create an AIDL file, I declare a method like this

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

Then Eclipse will auto generate a file IRemoteService.java and also return error:

cl cannot be resolved to a variable

Did I do something wrong?

Edit This is IRemoteService.java which auto generated.

/*
 * 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;
}

Thanks in advance.

10
  • 2
    What is aidl file? And could you post the whole trace
    – iTurki
    Aug 31, 2012 at 3:02
  • Hi, please have a look to this page: Android Interface Definition Language (AIDL) You will know what aidl file is.
    – NamPham
    Aug 31, 2012 at 3:27
  • Use CAPS! Now post the full trace.
    – iTurki
    Aug 31, 2012 at 3:30
  • Sorry, I don't know what CAPS is. you want to know how I did and what I receive from Eclipse, right?
    – NamPham
    Aug 31, 2012 at 3:34
  • CAPS: aidl -> AIDL :). Ans yes, post the error log you recieve from Eclipse.
    – iTurki
    Aug 31, 2012 at 3:45

1 Answer 1

0

The problem is in:

_result = _reply.readHashMap(cl);

Where cl can't be resolved to a variable because cl is defined locally in onTransact():

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

I don't know if auto-generated code means that it shouldn't be modified or it can't be modified. However, what I can tell you is this error will never go away unless you edited the code and:

  • Add another cl definition before the error line:

    java.lang.ClassLoader cl = (java.lang.ClassLoader)this.getClass().getClassLoader();
    _result = _reply.readHashMap(cl);
    
2
  • Thank you for you time. I have added the line above before the error line as you said, but Eclipse return error after I save file. The error is "IRemoteService.java was modified manually! Reverting to generated version!".
    – NamPham
    Sep 1, 2012 at 2:19
  • @NamPham Sorry. I can't think of anything else.
    – iTurki
    Sep 1, 2012 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.