لدي مشكلة في كود ولكن لا اعلم اين الخطاء بالتحديد في استرداد مواضيع المنتدى وهذا هوا الكود MainListActivity.java
حيت عملية تشغيل التطبيق عن طريق المحاكي تظهر لي الرسالة اللي قمت بإدخالها عندما لايكون هناك اتصال بالانترنت
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_list);
GetBlogPostTask getBlogPostTask = new GetBlogPostTask();
getBlogPostTask.execute();
// Toast.makeText(this, getString(R.string.no_itms). Toast.LENTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_list, menu);
return true;
}
private class GetBlogPostTask extends AsyncTask<Object, Void, String> {
@Override
protected String doInBackground(Object... params) {
int respnoseCode =-1;
try{
URL BlogFeedUrl = new URL("http://www.androidar.net/api/get_recent_summary/?count="+ NUMBER_OF_POSTS);
HttpURLConnection connection =(HttpURLConnection) BlogFeedUrl.openConnection();
connection.connect();
responseCode = connection.getResponseCode();
if (respnoseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
Reader reader = new InputStreamReader(inputStream);
int contentLength = connection.getContentLength();
char[] charArray = new char[contentLength];
reader.read(charArray);
String responseData = new String(charArray);
JSONObject jsonResponse = new JSONObject(responseData);
String status = jsonResponse.getString("status");
Log.v(TAG, status);
JSONArray jsonPosts = jsonResponse.getJSONArray("posts");
for (int i = 0 ; i < jsonPosts.length(); i++){
JSONObject jsonPost = jsonPosts.getJSONObject(i);
String title = jsonPost.getString("title");
Log.v(TAG, "Post " + i + "; " + title);
}
}
else {
Log.i(TAG,"Unsuccessful HTTP Response Code: " + responseCode);
}
}
catch (MalformedURLException e) {
Log.e(TAG , "Exception caught: " , e);
}
catch (IOException e){
Log.e(TAG , "Exception caught: " , e);
}
catch (Exception e){
Log.e(TAG , "Exception caught: " , e);
}
return "Code : "+ respnoseCode;
}
}
}