FATAL EXCEPTION: main
Haber sitesinden verileri volley kullanarak getirmeye calisdim ama bu hata ile karsilasdim.
MainActivity.java
[code]
public class MainActivity extends ActionBarActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final String url = "http://localhost/android/api.php";
private ProgressDialog pDialog;
private List<Xeberler> xeberList = new ArrayList<Xeberler>();
private ListView listView;
private CustomListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
adapter = new CustomListAdapter(this, xeberList);
listView.setAdapter(adapter);
pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1b1b1b")));
JsonArrayRequest movieReq = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
hidePDialog();
for(int i = 0; i < response.length(); i++){
try {
JSONObject obj = response.getJSONObject(i);
Xeberler xeberler = new Xeberler();
xeberler.setP_image(obj.getString("image"));
xeberler.setP_title(obj.getString("title"));
xeberler.setP_title_sonluq(obj.getString("title_sonluq"));
xeberler.setP_detail(obj.getString("detail"));
xeberList.add(xeberler);
} catch (Exception e) {
e.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "ERROR" + toString());
hidePDialog();
}
});
AppController.getInstance().addToRequestQueue(movieReq);
}
@Override
public void onDestroy() {
super.onDestroy();
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
[/code]
CustomListAdapter.java
[code]
public class CustomListAdapter extends BaseAdapter{
private Activity activity;
private LayoutInflater inflater;
private List<Xeberler> xeberItems;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public CustomListAdapter(Activity activity, List<Xeberler> xeberItems){
this.activity = activity;
this.xeberItems = xeberItems;
}
@Override
public int getCount() {
return xeberItems.size();
}
@Override
public Object getItem(int position) {
return xeberItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(inflater == null){
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if(convertView == null){
convertView = inflater.inflate(R.layout.xeberler, null);
}
if(imageLoader == null){
imageLoader = AppController.getInstance().getImageLoader();
}
NetworkImageView xeberFoto = (NetworkImageView) convertView.findViewById(R.id.thumbnail);
TextView xeberBasliq = (TextView) convertView.findViewById(R.id.titleBasliq);
TextView xeberSonluq = (TextView) convertView.findViewById(R.id.titleSonluq);
TextView xeberOzu = (TextView) convertView.findViewById(R.id.detail);
Xeberler xeberler = xeberItems.get(position);
xeberBasliq.setText(xeberler.getP_title());
xeberSonluq.setText(xeberler.getP_title_sonluq());
xeberFoto.setImageUrl(xeberler.getP_image(), imageLoader);
return convertView;
}
}
[/code]
activity_main.xml
[code]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.xeberapp.MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/xeberler" >
</ListView>
</LinearLayout>
[/code]
xeberler.xml
[code]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="134dp"
android:orientation="horizontal" >
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/thumbnail"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/titleBasliq"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#166CED" />
<TextView
android:id="@+id/titleSonluq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textColor="#F9065F"
android:textStyle="bold"/>
<TextView
android:id="@+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
[/code]