0

asynctask を分離してクラスを分離しましたが、結果を返すときにエラーが発生しました。インターフェイスを使用してコールバック機能を利用しようとしています。どこが間違っているか教えていただけますか?( line 40 is callback.onDeleteAdd(result); )

インターフェース

public interface DeleteAddInterface {
    public void onDeleteAdd(JSONObject result);
}

非同期タスク

public class DeleteAdd extends AsyncTask<Advert, Void, JSONObject> {
    private DeleteAddInterface callback;
    private int atempt = 0;
    private Advert advert;

    public DeleteAdd(int atempt) {
        this.atempt = atempt;
    }

    public DeleteAdd() {

    }

    @Override
    protected JSONObject doInBackground(Advert... advert) {
        this.advert = advert[0];
        if (atempt < 5) {
            UserFunctions u = new UserFunctions();
            return u.getNewAdd(advert[0].getId());
        } else
            return null;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        super.onPostExecute(result);
        if (result == null) {
            DeleteAdd add = new DeleteAdd(atempt + 1);
            add.execute(advert);
        } else {
            callback.onDeleteAdd(result);
        }
    }

}

アクティビティ

public class AddToCheckActivity extends ErrorActivity implements DeleteAddInterface{

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                DeleteAdd dAdd = new DeleteAdd();
        dAdd.execute(adv);

@Override
    public void onDeleteAdd(JSONObject result) {
        Intent i = new Intent(getApplicationContext(),
                MyAddPrepareActivity.class);
        startActivity(i);
        finish();

    }
}

エラー

10-27 02:16:26.322: E/AndroidRuntime(12664): FATAL EXCEPTION: main
10-27 02:16:26.322: E/AndroidRuntime(12664): java.lang.NullPointerException
10-27 02:16:26.322: E/AndroidRuntime(12664):    at networkOperations.DeleteAdd.onPostExecute(DeleteAdd.java:40)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at networkOperations.DeleteAdd.onPostExecute(DeleteAdd.java:1)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.os.AsyncTask.finish(AsyncTask.java:631)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.os.Looper.loop(Looper.java:158)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at android.app.ActivityThread.main(ActivityThread.java:5751)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at java.lang.reflect.Method.invokeNative(Native Method)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at java.lang.reflect.Method.invoke(Method.java:511)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
10-27 02:16:26.322: E/AndroidRuntime(12664):    at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1