bak güzel kardeşim aynı hatayı bende aldım ve uygulamayı telefonumda test ettim zaten.
MainActivity Kodları
[code]
package com.ahmetburak.jsonyemek;
import android.os.StrictMode;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class MainActivity extends ActionBarActivity {
private final String JSON_URL = "http://takvim.amasya.edu.tr/burak.php";
ArrayList<YemekMenu> menuList;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
menuList = new ArrayList<YemekMenu>();
String str = "";
HttpResponse response;
HttpClient myClient = new DefaultHttpClient();
HttpPost myConnection = new HttpPost(JSON_URL);
try {
response = myClient.execute(myConnection);
str = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try{
JSONArray jArray = new JSONArray(str);
for (int i = 0; i < jArray.length(); i++)
{
try {
JSONObject jsonObject = jArray.getJSONObject(i);
String kalori = jsonObject.getString("kalori");
String corba = jsonObject.getString("corba");
String anayemek = jsonObject.getString("anayemek");
String date = jsonObject.getString("date");
String meyve = jsonObject.getString("meyve");
String yemek = jsonObject.getString("yemek");
menuList.add(new YemekMenu(kalori, corba, anayemek, date, meyve, yemek));
}catch(JSONException e){
}
}
} catch ( JSONException e) {
e.printStackTrace();
}
Log.d("MainActivity",String.valueOf(menuList.size()));
}
}
[/code]
Buda YemekMenu
[code]
package com.ahmetburak.jsonyemek;
/**
* Created by Ahmet Burak on 20.6.2014.
*/
public class YemekMenu {
private String kalori,corba,anayemek,date,meyve,yemek;
public YemekMenu(String kalori, String corba, String anayemek, String date, String meyve, String yemek) {
this.kalori = kalori;
this.corba = corba;
this.anayemek = anayemek;
this.date = date;
this.meyve = meyve;
this.yemek = yemek;
}
public String getKalori() {
return kalori;
}
public void setKalori(String kalori) {
this.kalori = kalori;
}
public String getCorba() {
return corba;
}
public void setCorba(String corba) {
this.corba = corba;
}
public String getAnayemek() {
return anayemek;
}
public void setAnayemek(String anayemek) {
this.anayemek = anayemek;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getMeyve() {
return meyve;
}
public void setMeyve(String meyve) {
this.meyve = meyve;
}
public String getYemek() {
return yemek;
}
public void setYemek(String yemek) {
this.yemek = yemek;
}
}
[/code]