Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,149,828 members, 7,806,326 topics. Date: Tuesday, 23 April 2024 at 02:47 PM

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 (1188 Views)

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)

(1) (Reply) (Go Down)

Android Java Programmers, Please Help Me Look Into This by chukstem: 10:47am 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"wink;
}
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"wink+"\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: 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: 7:20am On Jan 02, 2016

(1) (Reply)

Delivering Suitable Ios App Development Solutions / In Need Of A Technical Co-founder / How To Protect Yourself From Petya/goldeneye Ransomware

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.