2 vampirecoding vampirecoding 于 2016.09.16 14:34 提问

Bmob后端云查询出错。

我在用bmob后端云来做一个app,在查询表的时候出现了上述问题。本意是想定义一个泛型的类来查询个种类的:

public  class BmobQueryUtils<T>{
    FindListeners<T> listeners;
    BmobQuery<T> query;
    Class<T> clazz;

    public List<T> queryColumnAll(String column){
        query.addQueryKeys(column);
        query.findObjects(listeners);
        return listeners.getLi();
    }

    public void setQueryAndListener(BmobQuery<T> query,FindListeners<T> listeners){
        this.query=query;
        this.listeners=listeners;
    }
}

还有自定义的FindListener

public  class FindListeners<T> extends FindListener<T> {
    private static final String TAG = "FindListeners";
    private List<T> li;
    @Override
    public void done(List<T> list, BmobException e) {
        if (null==e){
            li=list;
        }else {
            Log.e(TAG, "done: "+e.getMessage() );
        }
    }
    public List<T> getLi() {
        return li;
    }
}

结果这一句出现了异常TypeVariableImpl cannot be cast to java.lang.Class
并且该异常指向函数query.findObjects(listeners);,该函数的源码:

     public Subscription findObjects(FindListener<T> listener) {
        if(listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            Class var2 = (Class)((ParameterizedType)listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
            return this.Code((String)null, var2, (BmobCallback)listener);
        }
    }

还望知道的大神指点一下。

1个回答

niaonao
niaonao   Rxr 2016.09.16 17:02
  public Subscription findObjects(new FindListener<T> () {
        if(listener == null) {
            throw new IllegalArgumentException(" listener must not be null ");
        } else {
            Class var2 = (Class)((ParameterizedType)listener.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
            return this.Code((String)null, var2, (BmobCallback)listener);
        }
    });

应该new 实例化一个FindListener 对象

Csdn user default icon
上传中...
上传图片
插入图片