Android Java Programmers, Please Help Me Look Into This - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Android Java Programmers, Please Help Me Look Into This (1281 Views)
| Android Java Programmers, Please Help Me Look Into This by chukstem(op): 10:47am On Jan 01, 2016*. Modified: 11:33am On Jan 01, 2016 |
Please i am trying to fetch json data to populate into ListView from a server and am getting a null value. Plz what can be wrong as this is my first project on android. public void getdata(){ ListView listview=(ListView) findViewById(R.id.listview); String result=""; try{ Url url=new Url("http://www.url.com/forum.php"); URLConnection conn=url.openConnection(); conn.setDoOutput(true); BufferedReader rd=new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; StringBuilder sb=new StringBuilder(); while((line=rd.readLine())!=null){ sb.append(line+"\n" ;} rd.close(); result=sb.toString(); } catch(Exception e){ showAlart(e.getMessage()); } } try{ List<String>array=new ArrayList<String>(); String title=""; JSONArray jArray=new JSONArray(result); for(int i=0; i<jArray.length(); i++){ JSONObject json=jArray.getJSONObject(i); title=title+"title: "+json.getString("title" +"\n";array.add(title); } ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array); listview.setAdapter(adapter); } catch (Exception e){ } } |
| Re: Android Java Programmers, Please Help Me Look Into This by Nobody: 6:09pm On Jan 01, 2016 |
The last time I did Android was 2013 Looking at your code, everything seem right. Check the URL you are parsing to see the kind of JSON response you are getting or if it is returning JSON at all. |
| Re: Android Java Programmers, Please Help Me Look Into This by chukstem(op): 7:24pm On Jan 01, 2016 |
D server side is ohk. I just need sumbdy who has done sumtin lyk diz b4 to look into it |
| Re: Android Java Programmers, Please Help Me Look Into This by Nobody: 7:48pm On Jan 01, 2016 |
Change Url url=new Url(" http://www.url.com/ forum.php" ); to final String URL = "http://www.url.com" ; |
| Re: Android Java Programmers, Please Help Me Look Into This by Nobody: 7:51pm On Jan 01, 2016 |
Just try that |
| Re: Android Java Programmers, Please Help Me Look Into This by Nobody: 9:28pm On Jan 01, 2016 |
Paste your JSONArray here let's see. |
| Re: Android Java Programmers, Please Help Me Look Into This by chukstem(op): 7:20am On Jan 02, 2016 |
Help Me Look At This Small Problem • How Long Did It Take You Guys To Become Strong Java Programmers • Please Help Me Look At My Code • 2 • 3 • 4
What's Next! Ccna Security Or Niit MMS • How To Secure My Wireless Router • Database Error!
;