bluemunch bluemunch - 4 months ago 17
Java Question

Class is not abstract and does not override abstract method done(Object,Throwable) in ParseCallback2

I'm trying to do a ParseQuery in my RecyclerAdapter class:

// Differentiate between feedItem views and nativeAds
@Override
public int getViewType(int position) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("NativeAd");
query.whereEqualTo("objectId", "fYBeufqdOt");
final int[] n = new int[1];
query.getFirstInBackground(new GetCallback() {
@Override
public void done(ParseObject object, ParseException e) {
n[0] = Integer.valueOf(String.valueOf(object));
}
});

int viewType = VIEW_TYPE_MARKET_FEED;
if ((position % n[0] == 0) && position > 0) {
viewType = VIEW_TYPE_AD;
}
return viewType;
}


I get the following error in my RecyclerAdapter class:

Error:(75, 54) error: <anonymous com.elgami.market.MarketFeedRecyclerAdapter$1> is not abstract and does not override abstract method done(Object,Throwable) in ParseCallback2


What is going on? Should I perform the query elsewhere? If so, where and how?

Edit:

java.lang.ArithmeticException: divide by zero
at com.elgami.market.MarketFeedRecyclerAdapter.getViewType(MarketFeedRecyclerAdapter.java:84)
at com.elgami.utility.LoadingRowRecyclerAdapter.getItemViewType(LoadingRowRecyclerAdapter.java:41)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4960)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4913)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3260)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3069)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1505)
at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:151)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:305)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Answer

I think you need to specify the generic type of the class GetCallback

  @Override
  public int getViewType(int position) {
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("NativeAd");
    query.whereEqualTo("objectId", "fYBeufqdOt");
    final int[] n =  new int[1];
    query.getFirstInBackground(new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject object, ParseException e) {
            n[0] = Integer.valueOf(String.valueOf(object));
        }
    });

    int viewType = VIEW_TYPE_MARKET_FEED;
    if ((position % n[0] == 0) && position > 0) {
        viewType = VIEW_TYPE_AD;
    }
    return viewType;
}

see the doc

Comments