13

I think the code that I build for getting data from the server in JSON is not starting. In the logcat there is no text from "log.v". Also, the code that I made seems not good with the try-catch all the time. I use A query for the ajax request.

Have someone else have a problem with this?

I want to put the JSON into a hashmap so I can build a listview of it, but I can't get the data from the JSON into the logcat

Greetings

public class film_sound extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Get the view from fragmenttab1.xml
        View view = inflater.inflate(R.layout.activity_film_sound, container, false);
        Context context = inflater.getContext();
        String[] Film_Data =  getArguments().getStringArray("Film_Data");

        File ext = Environment.getExternalStorageDirectory();
        File cacheDir = new File(ext, "/android/data/be.moviechecker.programma/case");
        AQUtility.setCacheDir(cacheDir);
        final AQuery aq = new AQuery(context);

        /*Ophalen van de json*/
        String url = "http://app.be/data_2_0_0/sound.php?id=1";
        aq.ajax(url, JSONObject.class, new AjaxCallback<JSONObject>() {
            @Override
            public void callback(String url, JSONObject json, AjaxStatus status) {
                if (json != null) {
                    JSONArray jArray = null;
                    try {
                        jArray = json.getJSONArray("soundtrack");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    if (jArray.length() == 0) {
                        Log.v("debug", "dataleeg");
                    } else {
                        for (int i = 0; i < jArray.length(); i++) {
                            JSONObject json_data = null;
                            try {
                                json_data = jArray.getJSONObject(i);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            try {
                                Log.v("debug", json_data.getString("naam"));
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                } else {
                    //ajax error, show error code
                    Log.v("debug", aq.getContext() + "Error:" + status.getCode());
                }
            }
        });

        return view;
    }
}
Nmk
  • 1,281
  • 2
  • 14
  • 25
user3142817
  • 787
  • 2
  • 9
  • 15
  • 1
    It seems you're using wrong url. Try to open your url in browser (copy+paste). There is no json data returned, just an error that this page can't be found. In the same time `AQuery` is trying to cast returned data to json, that's why nothing was returned or logged. Try to use the proper url to get json data. – romtsn Jan 10 '16 at 20:34
  • 1
    it is not the real url, i get status 200 and json back from the php code – user3142817 Jan 11 '16 at 16:52
  • 1
    So, post then your **real** url, the community need to reproduce that issue, so we need all information to be able to resolve your issue. – romtsn Jan 11 '16 at 16:58
  • 1
    I just have run your code, and there was error logged into android logcat, 404 not found. So that code works perfectly. Maybe you just forgot to add internet permission to `AndroidManifest.xml` ? – romtsn Jan 12 '16 at 08:23
  • 1
    @rom4ek i have add the right permissions – user3142817 Jan 12 '16 at 19:07
  • So post then more code (activity, where is your fragment placed, manifest, xml, etc) – romtsn Jan 12 '16 at 19:30
  • @rom4ek it is a fragment of http://stackoverflow.com/questions/34484833/viewpager-wrap-content-not-working/34524240#34524240 – user3142817 Jan 13 '16 at 20:40
  • You should place that call in a `AsyncTask` and handle the request outer the `MainThread`. Could that make android kill the process because it is freezing the `MainThread`. – IgniteCoders Jan 14 '16 at 15:38
  • You can also try to do that call with a normal `HTTPRequest` and print the response in the LogCat. – IgniteCoders Jan 14 '16 at 15:40

1 Answers1

0

In phonegap you have to enable cross domain requests in config.xml

<access origin="http://domain.com/public/auth/app-login"/>

Maybe you can have a look at this:
WebView Javascript cross domain from a local HTML file

Community
  • 1
  • 1
Koen
  • 140
  • 1
  • 10