Unable To Fetch Data From Mysql Database To Listview In My Android Application
Solution 1:
There are a few things going on here, I'll try to address what I can.
This log entry is suspicious:
03-22 22:30:42.860: E/ERROR(6055): Illegal character in query at index 53: http://necrecords.16mb.com/getproducts.php?password=A AA E EEE
Also, from this log:
03-22 22:54:08.000:E/ERROR(7654):Error converting result java.lang.NullPointerException:lock==null
You can see that you are not getting a valid response from this PHP page.
This code block is throwing an exception:
//convert response to stringtry{
BufferedReaderreader=newBufferedReader(newInputStreamReader(is,"utf-8"),8);
StringBuildersb=newStringBuilder();
Stringline=null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("ERROR", "Error converting result "+e.toString());
I just tried the URL in a browser, and it worked, since the browser automatically encodes the url properly, like this:
http://necrecords.16mb.com/getproducts.php?password=A%20AA%20E%20EEE
I think that you just need to properly encode the URL since the string contains spaces.
Stringquery= URLEncoder.encode(mname, "utf-8");
httppost= newHttpPost("http://necrecords.16mb.com/getsongslist.php?password="+query);
response=httpclient.execute(httppost);
As for the issue of your list getting doubled, you could just clear the list each time the AsyncTask executes:
protected Void doInBackground(Void...params){
InputStream is=null;
String result="";
try{
records.clear(); //clear the list before re-populating
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://necrecords.16mb.com/getproducts.php");
response=httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
One more thing to mention, you will probably want to create a separate Adapter for each Acitvity. As it is now, you are using the same Adapter for both Activities.
In your Adapter's getView()
, you reference R.id.pro_name
and R.id.pro_uprice
, but you're using this Adapter in both of your Activities. Do both of your Activities contain these elements in their layout xml?
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflaterinflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewitemView= inflater.inflate(groupid, parent, false);
String[] row_items=records.get(position).split("__");
TextView textName= (TextView) itemView.findViewById(R.id.pro_name);
textName.setText(row_items[0]);
TextView textPrice= (TextView) itemView.findViewById(R.id.pro_uprice);
textPrice.setText(row_items[1]+"$");
return itemView;
}
Post a Comment for "Unable To Fetch Data From Mysql Database To Listview In My Android Application"