₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,007 members, 8,419,897 topics. Date: Thursday, 04 June 2026 at 06:45 AM

Toggle theme

Android Java Programmers, Please Help Me Look Into This - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingAndroid Java Programmers, Please Help Me Look Into This (1281 Views)

1 Reply (Go Down)

Android Java Programmers, Please Help Me Look Into This by chukstem(op):
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(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
1 Reply

Help Me Look At This Small ProblemHow Long Did It Take You Guys To Become Strong Java ProgrammersPlease Help Me Look At My Code234

What's Next! Ccna Security Or Niit MMSHow To Secure My Wireless RouterDatabase Error!