java - Android retrieving data from database error -
i totally new android ..and trying tutorial found online.basic aim retrieve data database , display it. not able execute .i have attached code , error log.it great if can rectify error.
<package com.example.androidhive; import java.util.arraylist; import java.util.hashmap; import java.util.list; import org.apache.http.namevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.app.listactivity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter; import android.widget.textview; public class allproductsactivity extends listactivity { // progress dialog private progressdialog pdialog; // creating json parser object jsonparser jparser = new jsonparser(); arraylist<hashmap<string, string>> productslist; // url products list private static string url_all_products = "192.168.0.1/android_connect/get_all_products.php"; // json node names private static final string tag_success = "success"; private static final string tag_products = "products"; private static final string tag_pid = "pid"; private static final string tag_name = "name"; // products jsonarray jsonarray products = null; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.all_products); // hashmap listview productslist = new arraylist<hashmap<string, string>>(); // loading products in background thread new loadallproducts().execute(); // listview listview lv = getlistview(); // on seleting single product // launching edit product screen lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // getting values selected listitem string pid = ((textview) view.findviewbyid(r.id.pid)).gettext() .tostring(); // starting new intent intent in = new intent(getapplicationcontext(), editproductactivity.class); // sending pid next activity in.putextra(tag_pid, pid); // starting new activity , expecting response startactivityforresult(in, 100); } }); } // response edit product activity @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); // if result code 100 if (resultcode == 100) { // if result code 100 received // means user edited/deleted product // reload screen again intent intent = getintent(); finish(); startactivity(intent); } } /** * background async task load product making http request * */ class loadallproducts extends asynctask<string, string, string> { /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(allproductsactivity.this); pdialog.setmessage("loading products. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } /** * getting products url * */ protected string doinbackground(string... args) { // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); // getting json string url jsonobject json = jparser.makehttprequest(url_all_products, "get", params); // check log cat json reponse log.d("all products: ", json.tostring()); try { // checking success tag int success = json.getint(tag_success); if (success == 1) { // products found // getting array of products products = json.getjsonarray(tag_products); // looping through products (int = 0; < products.length(); i++) { jsonobject c = products.getjsonobject(i); // storing each json item in variable string id = c.getstring(tag_pid); string name = c.getstring(tag_name); // creating new hashmap hashmap<string, string> map = new hashmap<string, string>(); // adding each child node hashmap key => value map.put(tag_pid, id); map.put(tag_name, name); // adding hashlist arraylist productslist.add(map); } } else { // no products found // launch add new product activity intent = new intent(getapplicationcontext(), newproductactivity.class); // closing previous activities i.addflags(intent.flag_activity_clear_top); startactivity(i); } } catch (jsonexception e) { e.printstacktrace(); } return null; } /** * after completing background task dismiss progress dialog * **/ protected void onpostexecute(string file_url) { // dismiss dialog after getting products pdialog.dismiss(); // updating ui background thread runonuithread(new runnable() { public void run() { /** * updating parsed json data listview * */ listadapter adapter = new simpleadapter( allproductsactivity.this, productslist, r.layout.list_item, new string[] { tag_pid, tag_name}, new int[] { r.id.pid, r.id.name }); // updating listview setlistadapter(adapter); } }); }`
error
07-18 02:55:17.809: d/dalvikvm(2205): gc_for_alloc freed 56k, 5% free 2815k/2944k, paused 106ms, total 107ms 07-18 02:55:17.839: i/dalvikvm-heap(2205): grow heap (frag case) 5.628mb 2949608-byte allocation 07-18 02:55:17.889: d/dalvikvm(2205): gc_for_alloc freed <1k, 3% free 5695k/5828k, paused 48ms, total 48ms 07-18 02:55:18.349: d/gralloc_goldfish(2205): emulator without gpu emulation detected. 07-18 02:55:21.079: d/dalvikvm(2205): gc_for_alloc freed 19k, 2% free 6529k/6620k, paused 86ms, total 87ms 07-18 02:55:22.309: w/dalvikvm(2205): threadid=12: thread exiting uncaught exception (group=0xb3a4fb90) 07-18 02:55:22.349: e/androidruntime(2205): fatal exception: asynctask #1 07-18 02:55:22.349: e/androidruntime(2205): process: com.example.androidhive, pid: 2205 07-18 02:55:22.349: e/androidruntime(2205): java.lang.runtimeexception: error occured while executing doinbackground() 07-18 02:55:22.349: e/androidruntime(2205): @ android.os.asynctask$3.done(asynctask.java:300) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.futuretask.setexception(futuretask.java:222) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.futuretask.run(futuretask.java:242) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) 07-18 02:55:22.349: e/androidruntime(2205): @ java.lang.thread.run(thread.java:841) 07-18 02:55:22.349: e/androidruntime(2205): caused by: java.lang.illegalstateexception: target host must not null, or set in parameters. scheme=null, host=null, path=192.168.0.1/android_connect/get_all_products.php 07-18 02:55:22.349: e/androidruntime(2205): @ org.apache.http.impl.client.defaultrequestdirector.determineroute(defaultrequestdirector.java:591) 07-18 02:55:22.349: e/androidruntime(2205): @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:293) 07-18 02:55:22.349: e/androidruntime(2205): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:555) 07-18 02:55:22.349: e/androidruntime(2205): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:487) 07-18 02:55:22.349: e/androidruntime(2205): @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:465) 07-18 02:55:22.349: e/androidruntime(2205): @ com.example.androidhive.jsonparser.makehttprequest(jsonparser.java:62) 07-18 02:55:22.349: e/androidruntime(2205): @ com.example.androidhive.allproductsactivity$loadallproducts.doinbackground(allproductsactivity.java:127) 07-18 02:55:22.349: e/androidruntime(2205): @ com.example.androidhive.allproductsactivity$loadallproducts.doinbackground(allproductsactivity.java:1) 07-18 02:55:22.349: e/androidruntime(2205): @ android.os.asynctask$2.call(asynctask.java:288) 07-18 02:55:22.349: e/androidruntime(2205): @ java.util.concurrent.futuretask.run(futuretask.java:237) 07-18 02:55:22.349: e/androidruntime(2205): ... 3 more 07-18 02:55:22.819: i/choreographer(2205): skipped 362 frames! application may doing work on main thread. 07-18 02:55:25.829: i/choreographer(2205): skipped 171 frames! application may doing work on main thread. 07-18 02:55:30.059: e/windowmanager(2205): android.view.windowleaked: activity com.example.androidhive.allproductsactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{b40ada18 v.e..... r.....id 0,0-461,175} added here 07-18 02:55:30.059: e/windowmanager(2205): @ android.view.viewrootimpl.<init>(viewrootimpl.java:346) 07-18 02:55:30.059: e/windowmanager(2205): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:248) 07-18 02:55:30.059: e/windowmanager(2205): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.dialog.show(dialog.java:286) 07-18 02:55:30.059: e/windowmanager(2205): @ com.example.androidhive.allproductsactivity$loadallproducts.onpreexecute(allproductsactivity.java:117) 07-18 02:55:30.059: e/windowmanager(2205): @ android.os.asynctask.executeonexecutor(asynctask.java:587) 07-18 02:55:30.059: e/windowmanager(2205): @ android.os.asynctask.execute(asynctask.java:535) 07-18 02:55:30.059: e/windowmanager(2205): @ com.example.androidhive.allproductsactivity.oncreate(allproductsactivity.java:57) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activity.performcreate(activity.java:5243) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activitythread.performlaunchactivity(activitythread.java:2140) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2226) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activitythread.access$700(activitythread.java:135) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activitythread$h.handlemessage(activitythread.java:1397) 07-18 02:55:30.059: e/windowmanager(2205): @ android.os.handler.dispatchmessage(handler.java:102) 07-18 02:55:30.059: e/windowmanager(2205): @ android.os.looper.loop(looper.java:137) 07-18 02:55:30.059: e/windowmanager(2205): @ android.app.activitythread.main(activitythread.java:4998) 07-18 02:55:30.059: e/windowmanager(2205): @ java.lang.reflect.method.invokenative(native method) 07-18 02:55:30.059: e/windowmanager(2205): @ java.lang.reflect.method.invoke(method.java:515) 07-18 02:55:30.059: e/windowmanager(2205): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:777) 07-18 02:55:30.059: e/windowmanager(2205): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:593) 07-18 02:55:30.059: e/windowmanager(2205): @ dalvik.system.nativestart.main(native method) 07-18 02:55:30.059: i/choreographer(2205): skipped 217 frames! application may doing work on main thread. 07-18 02:55:32.999: i/process(2205): sending signal. pid: 2205 sig: 9
this exception message:
java.lang.illegalstateexception: target host must not n\ ull, or set in parameters. scheme=null, host=null, path=192.168.0.1/android_connect/get_all_products.php
tells me makehttprequest
fails identify host parameter in url pass. go @titus advice , provide full url http://
prefix (or whatever protocol is). if type of error changes may have more 1 error.
Comments
Post a Comment