Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I do not know what happened, there is no error in my code, but the ListView in my application can not be displayed, if there are less than my code? This my project, ListView can't displayed.

enter image description hereenter image description here

Log Cat

07-16 03:50:57.016: W/System.err(1769): org.json.JSONException: Value <?xml of type java.lang.String cannot be converted to JSONObject
07-16 03:50:57.016: W/System.err(1769):     at org.json.JSON.typeMismatch(JSON.java:111)
07-16 03:50:57.016: W/System.err(1769):     at org.json.JSONObject.<init>(JSONObject.java:158)
07-16 03:50:57.016: W/System.err(1769):     at org.json.JSONObject.<init>(JSONObject.java:171)
07-16 03:50:57.016: W/System.err(1769):     at info.androidhive.slidingmenu.film.JSONParser.getObject(JSONParser.java:84)
07-16 03:50:57.016: W/System.err(1769):     at info.androidhive.slidingmenu.film.AmbilData.doInBackground(AmbilData.java:56)
07-16 03:50:57.016: W/System.err(1769):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-16 03:50:57.016: W/System.err(1769):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-16 03:50:57.016: W/System.err(1769):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-16 03:50:57.016: W/System.err(1769):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-16 03:50:57.016: W/System.err(1769):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-16 03:50:57.016: W/System.err(1769):     at java.lang.Thread.run(Thread.java:841)
07-16 03:50:57.164: W/EGL_genymotion(1769): eglSurfaceAttrib not implemented
07-16 03:50:57.576: W/EGL_genymotion(1769): eglSurfaceAttrib not implemented

config.php

<?php

$host="localhost";
$username = "root";
$password = "";
$db= "menufilm";

mysql_connect ($host,$username,$password) or die ("GAGAL");
mysql_select_db($db) or die ("database tidak ada");

?>

menu_service.php

<?php
require_once "config.php";
$json = array ();

$kategori=$_POST['kategori'];

$sqlselect="SELECT * FROM tb_menu WHERE idkategori=$kategori";
$hasil = mysql_query($sqlselect);
    while($row=mysql_fetch_assoc($hasil)){
            $menu[]=$row;
    }
    if (is_array($menu)) {
            $json['datamenu']=$menu;
            echo json_encode($json);
    }
?>

AmbilData.java

import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class AmbilData extends AsyncTask<Object, Object, Object> {
    private JSONParser jsonparser;
    ArrayList<String> d;
    JsonObjectResult jobres;
    Context context;
    ProgressDialog pd;

    public void init(Context c, JsonObjectResult jres, String kategori,
            String url) {
        this.context = c;
        this.jobres = jres;

        AmbilData ad = this;
        ad.execute(url, kategori, "");
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pd = ProgressDialog.show(context, "Retrieve Data", "aaa");
        pd.setMessage("Please wait...");
        pd.show();
    }

    @Override
    protected Object doInBackground(Object... parameter) {
        // TODO Auto-generated method stub
        JSONObject jsobj = null;
        String url = (String) parameter[0];
        String kat = (String) parameter[1];
        Log.i("url", url);
        Log.i("kat", kat);
        jsonparser = new JSONParser();
        List<NameValuePair> datajson = new ArrayList<NameValuePair>();
        datajson.add(new BasicNameValuePair("kategori", kat));
        try {
            jsobj = jsonparser.getObject(url, "POST", datajson);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return jsobj;
    }

    @Override
    protected void onPostExecute(Object result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        if (pd.isShowing()) {
            pd.dismiss();
        }

        if (result != null) {
            JSONObject js = (JSONObject) result;
            jobres.gotJsonObject(js);
        }
    }

    public static abstract class JsonObjectResult {
        public abstract void gotJsonObject(JSONObject jobject);
    }

}

MenuBaseAdapter.java

    import info.androidhive.slidingmenu.R;

    import java.io.InputStream;
    import java.util.ArrayList;

    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.AsyncTask;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;

    public class MenuBaseAdapter extends BaseAdapter {
    private static ArrayList<EntitasFilm> searchArrayList;

    private LayoutInflater mInflater;
    String urlpic = "http://192.168.43.24/menufilm/";

    Bitmap bm;

    public MenuBaseAdapter(Context context, ArrayList<EntitasFilm> results) {
        searchArrayList = results;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return searchArrayList.size();
    }

    @Override
    public Object getItem(int p) {
        return searchArrayList.get(p);
    }

    @Override
    public long getItemId(int p) {
        return p;
    }

    @Override
    public View getView (int p, View v, ViewGroup parent) {
        ViewHolder holder;

        if (v == null) {

        v = mInflater.inflate(R.layout.item_custom_listview, null);
        holder = new ViewHolder ();

        holder.judul = (TextView) v.findViewById(R.id.jdl_film);
        holder.rilis = (TextView) v.findViewById(R.id.rls_film);
        holder.pic = (ImageView) v.findViewById(R.id.poster);

        new DowloadImageTask().execute(urlpic+
searchArrayList.get(p).getPicFilm());
        v.setTag(holder);
        }else{
            holder = (ViewHolder) v.getTag();
        }

    holder.judul.setText(searchArrayList.get(p).getJudulFilm());
    holder.rilis.setText(searchArrayList.get(p).getRilisFilm());
        return v;

    }

    static class ViewHolder {
        TextView judul,rilis;
        ImageView pic;
    }

    public class DowloadImageTask extends AsyncTask<String,
Void, Bitmap> {
        ImageView bmImage;

        public void DownloadImageTask (ImageView bmImage) {
            this.bmImage = bmImage;
        }

        @Override
        protected void onPreExecute() {
            //TODO Auto-generated method stub
            super.onPreExecute();
        }

        protected Bitmap doInBackground (String ...
url) {
            String urldisplay = url [0];
            Bitmap mIcon11 = null;
            try {
            InputStream in = new
java.net.URL(urldisplay).openStream();
            mIcon11 =
    BitmapFactory.decodeStream (in);
            } catch (Exception e) {
                Log.e("ERROR", e.getMessage());
                e.printStackTrace();
                }
                return mIcon11;
                }
        protected void onPostExecute(Bitmap result) {
            if (result != null) {
                Bitmap bmp2 = 
    Bitmap.createScaledBitmap(result, 72, 72, true);
                bmImage.setImageBitmap(bmp2);
            }


            }
        }

    }

MenuActivity.java

package info.androidhive.slidingmenu.film;

import info.androidhive.slidingmenu.R;

import java.io.InputStream;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import info.androidhive.slidingmenu.film.AmbilData.JsonObjectResult;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MenuActivity extends Activity {
    EntitasFilm entitasfilm;
    ArrayList<EntitasFilm> menu = new ArrayList<EntitasFilm>();
    ListView lv;

    String url = "http://192.168.43.24/menufilm/menu_services.php";
    String urlpic = "http://192.168.43.24/menufilm/";

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_listview);

        lv = (ListView) findViewById (R.id.listMenu);

        Bundle b = this.getIntent().getExtras();
        if (b.containsKey("kategori")) {

        String kat = b.getString("kategori");
        Log.d("kat", kat);
        AmbilData ambildata = new AmbilData();
        ambildata.init(MenuActivity.this,jsresult, kat,url);
        }
    }

    public JsonObjectResult jsresult = new JsonObjectResult(){

        @Override
        public void gotJsonObject (JSONObject jobject) {
            //TODO Auto-generated method stub
    try {
        JSONArray arraytempat = jobject.getJSONArray("datamenu");
    for (int i=0; i < arraytempat.length(); i++) {
        entitasfilm = new EntitasFilm ();
        entitasfilm.setIDfilm(
arraytempat.getJSONObject(i).getInt("idmenu"));
        entitasfilm.setJudulFilm(
arraytempat.getJSONObject(i).getString("judulfilm"));
        entitasfilm.setGenreFilm(
arraytempat.getJSONObject(i).getString("genrefilm"));
        entitasfilm.setStdrFilm(
arraytempat.getJSONObject(i).getString("stdrfilm"));
        entitasfilm.setPemainFilm(
arraytempat.getJSONObject(i).getString("pemainfilm"));
        entitasfilm.setRilisFilm(
arraytempat.getJSONObject(i).getString("rilisfilm"));
        entitasfilm.setDurasiFilm(
arraytempat.getJSONObject(i).getString("durasifilm"));
        entitasfilm.setSinopsisFilm(
arraytempat.getJSONObject(i).getString("sinopsisfilm"));
        entitasfilm.setPicFilm(
arraytempat.getJSONObject(i).getString("picfilm"));

        menu.add (entitasfilm);
        }
        } catch (JSONException e1) {
            //TODO Auto-generated catch block
                e1.printStackTrace();
        }

        MenuBaseAdapter datatempat = new
                MenuBaseAdapter(MenuActivity.this, menu);
        lv.setAdapter(datatempat);
        lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
int p, long arg3) {
            String jd = menu.get(p).getJudulFilm();
            String ge = menu.get(p).getGenreFilm();
            String st = menu.get(p).getStdrFilm();
            String pe = menu.get(p).getPemainFilm();
            String ri = menu.get(p).getRilisFilm();
            String du = menu.get(p).getDurasiFilm();
            String si = menu.get(p).getSinopsisFilm();
            String pic = menu.get(p).getPicFilm();
            tampilkandetail (jd,ge,st,pe,ri,du,si,pic);
                            }
                    });
            }
        };
        public void tampilkandetail (String judul, String Genre, String stdr, String pemain,
String rilis, String durasi, String sinop, String pic ) {
            final Dialog d = new Dialog(this);
            d.setTitle ("Detail");
            d.setContentView(R.layout.dialog_custom);
            WindowManager.LayoutParams lp = new
    WindowManager.LayoutParams();
            lp.copyFrom(d.getWindow().getAttributes());
            lp.width = LayoutParams.MATCH_PARENT;
            lp.height = LayoutParams.WRAP_CONTENT;
            d.getWindow().setAttributes(lp);
            ImageView gb = (ImageView)
    d.findViewById(R.id.picDialog);
            TextView j = (TextView)
    d.findViewById(R.id.idJudul);
            TextView s = (TextView)
    d.findViewById(R.id.idGenre);
            TextView g = (TextView)
    d.findViewById(R.id.idStdr);
            TextView pem = (TextView)
    d.findViewById(R.id.idPemain);
            TextView ril = (TextView)
    d.findViewById(R.id.idRilis);
            TextView sin = (TextView)
    d.findViewById(R.id.idSinopsis);
            Button bOk = (Button)
    d.findViewById(R.id.idOK);

            j.setText(judul);
            g.setText(Genre);
            s.setText(stdr);
            pem.setText(pemain);
            ril.setText(rilis);
            sin.setText(sinop);
            new DowloadImageTask(gb).execute(urlpic + pic);
            bOk.setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View v){
                    d.dismiss();
                }
                });
            d.show();
            }

    public class DowloadImageTask extends
    AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;
    public DowloadImageTask(ImageView bmImage){
        this.bmImage = bmImage;
        }
    @Override
    protected void onPreExecute() {
        //TODO Auto-generated method stub
        super.onPreExecute();
    }

    protected Bitmap doInBackground(String... urls) {
        String urldispaly = urls[0];
        Bitmap mIcon11 = null;
        try {
        InputStream in = new
java.net.URL(urldispaly).openStream();
        mIcon11 =
    BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error",
        e.getMessage());
            e.printStackTrace();
                    }
                    return mIcon11;
        }
    protected void onPostExecute(Bitmap result) {
        if (result != null) {
            Bitmap bmp2 =
    Bitmap.createScaledBitmap (result, 72, 72, true);

            bmImage.setImageBitmap(bmp2);
                            }
                    }
            }
}

JSONParser.java

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONParser {

    InputStream is;
    String json;

    JSONObject object;

    public JSONObject getObject(String url, String method, List<NameValuePair> value)  throws IOException {

        if(method == "POST"){
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(url);
            try {
                post.setEntity(new UrlEncodedFormEntity(value));
                HttpResponse response = client.execute(post);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();   
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }else if(method == "GET"){
        DefaultHttpClient client = new DefaultHttpClient();
        String param = URLEncodedUtils.format(value, "utf-8");
        url += "?" + param;
        HttpGet get = new HttpGet(url);
        HttpResponse response;
        try {
            response = client.execute(get);
            is = response.getEntity().getContent();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"));
            StringBuilder sb = new StringBuilder();
            String line;
            while((line = reader.readLine())!=null){
                sb.append(line+"\n");
            }
            is.close();
            json = sb.toString();
            object = null;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            object = new JSONObject(json);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return object;
    }

}

Please help, i dont know what happen :(

share|improve this question
    
your response is not in json format. CHeck it – Raghunandan Jul 16 '14 at 4:11
    
so, what should i do? @Raghunandan – Ruhbi Anugrah P Jul 16 '14 at 4:13
    
check the server side. get the json and then parse – Raghunandan Jul 16 '14 at 4:14
    
where i check it? @Raghunandan – Ruhbi Anugrah P Jul 16 '14 at 4:22
    
where do you have json sent from – Raghunandan Jul 16 '14 at 5:19
up vote 0 down vote accepted

First of all try to print json response in your log cat. Always follow this step so that will be easy to get the things faster. Are you getting any exception while getting response from webservice? If so, show log cat over here.

share|improve this answer
    
I have an update my post maybe you can help me – Ruhbi Anugrah P Jul 16 '14 at 4:10
    
I think your are getting response in xml format. So you need to convert that response in our json for that you need to apply your logic. Here I'm providing you link, I'm pretty sure this will solve your problem. stackoverflow.com/questions/16663389/… – VVB Jul 16 '14 at 4:14
    
The link you gave, code getting JSON response to be covered by the XML, where i inserted codes? – Ruhbi Anugrah P Jul 16 '14 at 4:21
    
I'm not getting your last comment/question. Elaborate it. – VVB Jul 16 '14 at 4:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.