I have a class called DownloadData it's passed from a fragment. It downloads all the JSON data I need and stores them to SQLite DB, it's working fine. But, when I pass the function to populate on my ListView, my app crashes. I added it to the onViewCreated method, it throws NullPointerException meaning the Database is empty, but when I add it to the end of the method in the class that helps download my data. java.lang.IllegalStateException: Fragment. My code is below:
Public class DataRetrieval{
handleJson();
public void handleResponse {
//My work goes here.....
getResults();
}
}
Public class PendingFragment extends ListFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
DataRetrieval ord = new DataRetrieval(getActivity());
ord.handleResponse();
}
public void getResults(){
Uri uri = Uri.parse("content://" + getString(R.string.AUTORITY_ORDER) + "/orders");
String dbUri = uri.toString();
ContentProvider cp = null;
final Cursor cursor = cp.query(uri, null, null, null, "_id");
}
@Override
public void onDetach() {
// TODO Auto-generated method stub
super.onDetach();
try {
Field child1 = Fragment.class.getDeclaredField("PENDING");
child1.setAccessible(true);
child1.set(this, null);
} catch (NoSuchFieldException e) {
// TODO: handle exception
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
Below is my Logcat
09-14 11:23:47.146: E/AndroidRuntime(25124): java.lang.IllegalStateException: Fragment PendingFragment{41e34b00} not attached to Activity
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.support.v4.app.Fragment.getResources(Fragment.java:603)
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.support.v4.app.Fragment.getString(Fragment.java:625)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.deliveryscience.pod.fragments.PendingFragment.getResults(PendingFragment.java:75)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.deliveryscience.pod.handlers.OrderDataRetrieval.handleResponse(OrderDataRetrieval.java:117)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.deliveryscience.pod.handlers.OrderDataRetrieval$1.onResponse(OrderDataRetrieval.java:42)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.deliveryscience.pod.handlers.OrderDataRetrieval$1.onResponse(OrderDataRetrieval.java:1)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.os.Handler.handleCallback(Handler.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.os.Handler.dispatchMessage(Handler.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.os.Looper.loop(Looper.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at android.app.ActivityThread.main(ActivityThread.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 11:23:47.146: E/AndroidRuntime(25124): at java.lang.reflect.Method.invoke(Method.java:515)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
09-14 11:23:47.146: E/AndroidRuntime(25124): at dalvik.system.NativeStart.main(Native Method)
0 comments:
Post a Comment