First of all thanks for reading my question.
Right now i am implementing the web services to my android app using OKHTTP. App is running fast if i am using Fast internet. In slow internet I got data slowly thats also fine. But issue is if i switch one activity to another activity without waiting for data in response of data call. At that time it is not able to find the current control and throw the exception NullPointer. what to do in this type of situation to manage the NullPointer Error.
It find the previous activity ui control in Current activity to set data.
FATAL EXCEPTION: OkHttp Dispatcher
Process: in.cess, PID: 16535
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference
at in.cess.fragment.WorkRequestCompletedFragment.onResponse(WorkRequestCompletedFragment.java:221)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Activity Code for response.
this.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter = new CallAdapter(getActivity(),movieList,
new CallAdapter.OnItemClickListener() {
@Override
public void onFeedClicked(CallDeatails jobDetails) {
Intent i = new Intent(getActivity(), SalesCallDetailsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Const.INTENT_DATA,jobDetails);
i.putExtra(Const.INTENT_TODAY,"true");
getActivity().startActivity(i);
}
});
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
txt_total_call.setText("Total Call : "+String.valueOf(movieList.size()));
}
});