Although this is just a rough sketch..i just want to see if it will work..Anytime i run the program it doesn't crash and it doesn't show anything. The error showing on the logcat is JSON result form the php page..i don't know why the Postexecute() method is not working...
this is the error
09-14 18:21:07.079: E/JSON(21310): {"tag":"getTopic","success":1,"error":0,"data":[{"title":"Facebook finally rolls GRAPH Search","tid":"81","time":"2013-06-22 10:05:18"},{"title":"What is Ubuntu for Android?","tid":"69","time":"2013-06-22 10:18:00"},{"title":"Android and Windows on same device(samsung)","tid":"98","time":"2013-06-22 10:18:35"},{"title":"\"Tweet\" has been verified as a real word in English","tid":"67","time":"2013-06-22 10:27:33"},{"title":"Instagram now has video recording","tid":"97","time":"2013-06-22 10:27:45"},{"title":"An Open Letter to DBanj","tid":"70","time":"2013-06-22 10:31:41"},{"title":"MTN call rate wahala","tid":"84","time":"2013-06-22 10:32:44"},{"title":"Types of friends essential for women","tid":"33","time":"2013-06-22 10:45:41"},{"title":"Not to be loved in return","tid":"106","time":"2013-06-22 18:15:06"},{"title":"I am in love with you","tid":"107","time":"2013-06-22 18:28:56"},{"title":"I hate it!!!","tid":"115","time":"2013-06-23 19:06:26"},{"title":"Spoils of love","tid":"116","time":"2013-06-23 19:14:43"},{"title":"An Apology Letter from Men To Women","tid":"117","time":"2013-06-26 12:43:02"},{"title":"Ramadan Starts tomorrow (in sha Allah) !!!","tid":"120","time":"2013-07-09 15:06:09"},{"title":"Preventing infidelity on your marriage","tid":"29","time":"2013-07-14 12:06:31"},{"title":"How to have a healthy relationship","tid":"121","time":"2013-08-02 17:17:32"},{"title":"ASUU strike not ending anytime soon","tid":"124","time":"2013-08-27 12:56:26"},{"title":"Google Announces Android 4.4 KitKat","tid":"126","time":"2013-09-06 20:51:32"},{"title":"Apple Launches iPhone 5s and iPhone 5c","tid":"127","time":"2013-09-11 15:29:40"}]}
and this is the class
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.nairation.library.JSONParser;
import com.nairation.library.UserFunctions;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class Topic_page extends Activity implements OnItemClickListener{
public static final String TOPIC_DURATION = "relative";
public static final String TOPIC_TITLE = "title";
public static final String TOPIC_PREVIEW = "Testing out";
public static final String TOPIC_ID = null;
public static final Object TOPIC_THUMB_URL = null;
ListView list;
TopicListAdapter adapter;
UserFunctions userf;
JSONParser jpa;
ArrayList<HashMap<String, String>> topicList = new ArrayList<HashMap<String,String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.topic_page);
list = (ListView) findViewById(R.id.topic_list);
adapter = new TopicListAdapter(this, topicList);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
try{
new ServiceSync().execute("mash");
}catch(Exception e){
String message = e.getMessage();
}
}
private class ServiceSync extends AsyncTask<String, JSONObject, JSONObject>{
@Override
protected JSONObject doInBackground(String... params) {
// TODO Auto-generated method stub
String uname = params[0];
userf = new UserFunctions();
JSONObject jp = userf.getTopic(uname);
return jp;
}
@Override
protected void onPostExecute(JSONObject result) {
// TODO Auto-generated method stub
//super.onPostExecute(result);
try {
JSONArray obj = result.getJSONArray("data");
for (int i = 0; i < result.length(); i++) {
JSONObject data = obj.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
String title = data.getString(TOPIC_TITLE);
String time = data.getString("time");
String tid = data.getString("tid");
map.put(TOPIC_TITLE, title);
map.put("Date", time);
topicList.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Problem with loading the feeds", Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
}
}
So what could be the problem the JSON result is not being processed..