In my application i have been using retrofit for my webservice calls. It is not working fine. This is the error that caused when my application started
04-16 07:41:26.162 5860-5860/com.pance.taugaksih E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at com.pance.taugaksih.activity.SplashscreenActivity$1.success(SplashscreenActivity.java:54) at com.pance.taugaksih.activity.SplashscreenActivity$1.success(SplashscreenActivity.java:42) at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)
This is my code that callled retrofit with response NullpointerExeption
RESTClient.get().getPost(new Callback<ResponsePost>() {
@Override
public void failure(RetrofitError error) {
// TODO Auto-generated method stub
progress.dismiss();
Toast.makeText(getApplicationContext(), "AKSES KE SERVER GAGAL" + error.getMessage(), Toast.LENGTH_LONG).show();
finish();
}
@Override
public void success(ResponsePost post, Response response) {
// TODO Auto-generated method stub
if (post.getPost().size() > 0) {
PostController chb = new PostController(myContext);
chb.open();
chb.deleteData();
for (int y = 0; y < post.getPost().size(); y++) {
PostModel tmpHasil = post.getPost().get(y);
chb.insertPost(tmpHasil);
}
chb.close();
Intent sendIntent = new Intent(myContext,PostActivity.class);
startActivity(sendIntent);
finish();
} else {
Toast.makeText(getApplicationContext(), "DATA SEDANG TIDAK TERSEDIA", Toast.LENGTH_LONG).show();
}
progress.dismiss();
}
});
And this is code my RESTClient class
public class RESTClient {
private static APIPost REST_CLIENT;
private static String URL_TAUGAKSIH = "http://10.108.109.30/taugaksih_slim";
static {
setupRestClient();
}
private RESTClient() {}
public static APIPost get() {
if(REST_CLIENT==null){
setupRestClient();
}
return REST_CLIENT;
}
private static void setupRestClient() {
RestAdapter builder = new RestAdapter.Builder().setEndpoint(URL_TAUGAKSIH).build();
REST_CLIENT = builder.create(APIPost.class);
}
}