android - Same code gives different result in different Activities while pulling JSON data through AsyncTask -


This is my simple code snippet for dragging JSON data from my local host

  public Category JSONtest ​​ActionBarActivity Extended {Personal Progress Dialog dialog; String message3; String message_shore; String [] items; String [] short_items; TextView TV; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_jsontest); String localhost = "http://10.0.2.2/example/json/notification.php"; Tv = (TextView) findViewById (R.id.textView1); New ReadJSONFeedTask () Executed (localhost); } Private class readJSONFeedTask AsyncTask and lt; String, zero, string & gt; {Safe on xxaxite} {Super. Prairac (); Dialog = new progression (JSONtest.This); Dialog.setMessage ("Downloading information please wait ..."); Dialog.setIndeterminate (false); Dialog.setCancelable (incorrect); Dialog.show (); } Protected string doInBackground (string ... url) {returns jasonfid (url [0]); } Secure Execute on zero (string result) {dialog.dismiss (); Try {JSONArray jsonArray = New JSONArray (Results); Item = new string [jsonArray.length ()]; Short_items = new string [jsonArray.length ()]; For (int i = 0; i & lt; jsonArray.length (); i ++) {JSONObject jobj = jsonArray.getJSONObject (i); Message 3 = "Part 1:" + Jouge.Get String ("Subject") + "\ n \ n" + "Part 2:" + Jaw .get String ("Date"); Item [i] = message3; Message_short = message_short + "\ n \ n" + Message 3; }} Hold (exception e) {e.printStackTrace (); } Tv.setText (message_short); }} Public string readJSonFeed (string url) {stringbirder sb. = New stringbilder (); HTTP Client Client = New DefaultHttpClient (); HTTPGet HG = New HTTPGet (URL); Try {HttpResponse response = client.execute (hg); Threaded Positions = Response .getStatusLine (); Int statusCode = statusLine.getStatusCode (); If (statusCode == 200) {HttpEntity n = response.getEntity (); InputStream content = en.getContent (); BufferedReader Reader = New BufferedReader (New InputStreamReader (Content)); String line; While ((line = reader. Readline ()) = null (); {sb.append (line); }} Else {Log.e ("JSON", "Failed to download file"); }} Catch (Client Protocol E) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Return sb.toString (); }}  

I used this exact code in two different activities in the same app. The only difference was the name of the squares, whereas one activity works right, another activity causes the error because nothing happens and the TextView is left black, the logger entry for the activity which does not work This is:

  11-04 11: 14: 40.679: W / AGL_mulation (2925): Egglifffet has not been implemented 11-04 11:14: 40.749: W / System.err (2925): java.lang.NullPointerException 11-04 Nov: 14:40: 40.749: W / System.err (2925): com.onclaveinc.ioexception.HomeScreen $ ReadJSONFeedTask.onPostExecuteP (HomeScreen.java: 129) Nov 11-04: 14: 40.749: W / System.err (2925): $ ReadJSONFeedTask.onPostExecute (HomeScreen.java:1) at com.onclaveinc.ioexception.HomeScreen 11-04 Nov: 14 : 40.749: W / System.err (2925): android.os.AsyncTask.finish at (AsyncTask.java:632) 11-04 11: 14: 40.749: W / System.err (2925): android.os at. AsyncTask.access $ 600 (AsyncTask.java:177) 11-04 11:14 14:40: 40.749: W / System.err (2925): $ internalHandler.handleMessage (asyncTask.java:645) on android.os.AsyncTask 11-04 11: 14: 40.749: W / Systems. ARR (2925): Android.OS Handler DCPatch Message (Handler. Java 10 2) 11-04 11: 14: 40.74 9: W / Systems. Er (2925): Android. Loop (Looper.java:1236) Nov 11-04: 14: 40.749: W / System.err (2925): 14: 40.749: android.app.ActivityThread.main (ActivityThread.java ** 017) November 11-04 ( 2925) W / System.err: Java.lang.reflect.Method.invokeNative at (native method) 11-04 11: 14: 40.74 9: W / system. Er (2925): at java.lang.reflect.Method.invoke (Method .Java Author) 11-04 Nov: 14: 40.749: W / System.err (2925): at com.android.internal.os. ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:779) 11-04 11: 14: 40.749: W / System.err (2 9 25): com.android.internal.os.ZygoteInit.main (ZygoteInit.java lesson9) 11 -04 11: 14: 40.76 9: W / Systems. Er (2925): .main on the Dalvik.system.NativeStart (the original method)  

Can someone help me with this? I really need both to work really.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -