==================== Problem Description ====================
Transfer data (Title,imgurl,account) when transferring the title or Title+account, the data is transmitted normally, but the Imgurl item cannot be transferred, even if the imgurl+title is the same, no data is displayed
Ask
1.httpcon.java copy content to Clipboard code:
Data interaction, input and output streams and read streams
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.OutputStream;
Import java.net.HttpURLConnection;
Import Java.net.URL;
Import java.util.ArrayList;
public class httpcon{
Public Arraylist<string>getwebserver (String methodname,arraylist<string> parameters,arraylist< String> paravalues) {
Arraylist<string> Values =new arraylist<string> ();
SOAP format
String serverurl= "Http://10.0.2.2:58665/Service1.asmx";
String soapaction = "http://tempuri.org/" + methodName;
String soap = "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>"
+ "<soap:envelope xmlns:xsi=\" http://www.w3.org/2001/xmlschema-instance\ "xmlns:xsd=\" http://www.w3.org/2001/ Xmlschema\ "xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\ ">"
+ "<soap:body/>";
String TPS, VPS, TS;
String mreakstring = "";
mreakstring = "<" + MethodName + "xmlns=\" http://tempuri.org/\ ">";
for (int i =0; i < parameters.size (); i++)
{
TPS = Parameters.get (i). toString ();
VPS = Paravalues.get (i). toString ();
Ts= "<" + TPS + ">" + VPS + "</" + TPS + ">";
mreakstring = Mreakstring +ts;}
mreakstring = mreakstring + "</" + MethodName + ">";
String soap2 = "</soap:Envelope>";
String requestData = soap + mreakstring + soap2;
Connect WebService, data interaction
Try{url url = new URL (serverurl);
HttpURLConnection con = (httpurlconnection) url.openconnection ();
byte[] bytes = requestdata.getbytes ("Utf-8");
Con.setdoinput (TRUE);
Con.setdooutput (TRUE);
Con.setusecaches (FALSE);
Con.setconnecttimeout (6000);//Set timeout time
Con.setrequestmethod ("POST");
Con.setrequestproperty ("Content-type", "text/xml;charset=utf-8");
Con.setrequestproperty ("SOAPAction", SOAPAction);
Con.setrequestproperty ("Content-length", "+bytes.length");
OutputStream OutStream = Con.getoutputstream ();
Outstream.write (bytes);
Outstream.flush ();
Outstream.close ();
InputStream instream = Con.getinputstream ();
Read Stream class Call
Values = Inputstreamtovaluelist (instream, methodName);
return Values;
} catch (Exception e) {
System.out.print ("2221");
System.out.print ("2221");
return null;}}
Read stream
Public arraylist<string> inputstreamtovaluelist (InputStream in, String methodName) throws IOException {
StringBuffer out = new StringBuffer ();
String S1 = "";
Byte[] B = new byte[4096];
arraylist<string> Values = new arraylist<string> ();
Values.clear ();
for (int n; (n = in.read (b))! =-1;) {
S1 = new String (b, 0, N);
Out.append (S1);
}
System.out.println (out);
string[] S13 = S1.split ("><");
String ifstring = methodName + "Result";
String TS = "";
String vs = "";
Boolean Getvalueboolean = false;
for (int i = 0; i < s13.length; i++) {
TS = S13;
System.out.println (TS);
Int J, K, L;
j = Ts.indexof (ifstring);
K = Ts.lastindexof (ifstring);
if (J >= 0) {
System.out.println (j);
if (Getvalueboolean = = False) {
Getvalueboolean = true;
} else {
}
if ((J >= 0) && (k > J)) {
System.out.println ("FFF" + ts.lastindexof ("/" + ifstring));
System.out.println (TS);
L = ifstring.length () + 1;
vs = Ts.substring (j + L, k-2);
System.out.println ("FFF" +vs);
Values.add (VS);
System.out.println ("exit" + vs);
Getvalueboolean = false;
System.out.println ("one");
return Values;
}
}
if (Ts.lastindexof ("/" + ifstring) >= 0) {
Getvalueboolean = false;
return Values;
}
if ((Getvalueboolean) && (Ts.lastindexof ("/" + Ifstring) < 0) && (J < 0)) {
K = Ts.length ();
System.out.println (TS);
vs = Ts.substring (7, k-8);
System.out.println ("F" +vs);
Values.add (VS);
} }
System.out.println ("two");
return Values;
}}
2.dbutil.java copy content to Clipboard code:
It's a logical layer.
Import java.sql.Connection;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
public class Dbutil {
Private arraylist<string> ArrayList = new arraylist<string> ();
Private arraylist<string> brraylist = new arraylist<string> ();
Private arraylist<string> crraylist = new arraylist<string> ();
Private arraylist<string> drraylist = new arraylist<string> ();
Private Httpcon http = new Httpcon ();
/* Paste only a useful two calls */
Ej.java Call
Public listlistArraylist.clear ();
Brraylist.clear ();
Crraylist.clear ();
Arraylist.add ("Ztz");
Brraylist.add (Ztz);
System.out.println ("This is" +brraylist);
Crraylist = http. Getwebserver ("Ejym", ArrayList, brraylist);//SOAP format
Method name, parameter name, value of argument
System.out.println ("Crraylist" +crraylist);
if (crraylist!=null) {
for (int j = 0; J < crraylist.size (); j+=1) {
hashmap<string, string> HashMap = new hashmap<string, string> ();
Hashmap.clear ();
Hashmap.put ("Biaoti", Crraylist.get (j));
Hashmap.put ("url", Crraylist.get (j+1));
List.add (HASHMAP);
}}
Else{system.out.println ("Substance");}
SYSTEM.OUT.PRINTLN ("list" +list);
return list;}
Mainactivity.java called, the Imgurl is passed as the parameter
Public string[] Tpxw () {
list
Arraylist.clear ();
Brraylist.clear ();
Crraylist.clear ();
Crraylist = http. Getwebserver ("Tpxw", ArrayList, brraylist);//soap format
println ("Picture News" +crraylist);
String[] A=new string[5];
if (crraylist!=null) {
for (int j = 0; J < Crraylist.size (); j + +) {
a[j]= "Http://10.0.2.2:56041/Web" +crraylist.get (j);//complement path, imgurl stored as relative path
return A;}
}
3.mainactivity.java Main code
Copy content to Clipboard code:
Show network pictures, get Imgurl path from Dbutil.ava
Gallery gallery= (Gallery) Findviewbyid (r.id.gallery);
try {
Set the adapter of gallery
Gallery.setadapter (New Galleryadapter (this));
Gallery.setselection (0);//Set the first icon to center
Gallery.setspacing (00);//distance between icons
} catch (IllegalArgumentException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();}
public class Galleryadapter extends Baseadapter {
Private string[] Myimageurl = Dbutil_1.tpxw ();//imgurl transmission OK
Gallery format
Public Galleryadapter (Context c) {
Mcontext=c;
}
@Override
public int GetCount () {
TODO auto-generated Method Stub
return myimageurl.length;
}
@Override
Public Object getItem (int position) {
TODO auto-generated Method Stub
return position;
}
@Override
public long getitemid (int position) {
TODO auto-generated Method Stub
return position;
} @Override
Public View GetView (int position, View Convertview, ViewGroup parent) {
TODO auto-generated Method Stub
ImageView ImageView = new ImageView (this.mcontext);
try{
URL Aryuri = new URL (myimageurl[position]);
Open connection
URLConnection conn = Aryuri.openconnection ();
Conn.connect ();
Change to InputStream
InputStream is = Conn.getinputstream ();
Turn the InputStream into a bitmap
Bitmap BM = Bitmapfactory.decodestream (IS);
Close InputStream
Is.close ();
Add a picture
Imageview.setimagebitmap (BM);
} catch (IOException e)
{
E.printstacktrace ();
}
Setting Layout parameters
Imageview.setlayoutparams (New Gallery.layoutparams (350, 300));
return imageView;
}}
4.ej.java copy content to Clipboard code:
Call Dbutil.ava to display the resulting Imgurl data in a ListView
Import java.io.IOException;
Import Java.io.InputStream;
Import java.net.MalformedURLException;
Import Java.net.URL;
Import java.util.ArrayList;
Import Java.util.Arrays;
Import Java.util.HashMap;
Import java.util.List;
Import java.lang.string.*;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.ViewGroup;
Import Android.widget.AdapterView;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.ListView;
Import Android.widget.ScrollView;
Import Android.widget.SimpleAdapter;
Import Android.widget.TextView;
Import Android.widget.Toast;
Import Android.widget.AdapterView.OnItemClickListener;
Import android.content.Intent;
public class EJ extends Activity {
Private TextView Stvtitle;
Private ListView SLV;
Private Dbutil Dbutil_1;
Private Simpleadapter adapter;
Private list/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.LAYOUT.EJYM);
Intent, there's no code in here, but there's definitely no problem with the transfer of parameters.
String YH = null;
Final String ej1 = It.getstringextra (YH);
Stvtitle= (TextView) Findviewbyid (r.id.stvtitle);
slv= (ListView) Findviewbyid (R.ID.SLV);
Stvtitle.settext (EJ1);
listList1.clear ();
try{
Dbutil_1=new dbutil ();//Instantiation of Class
List1=dbutil_1.ejym (EJ1);
System.out.println ("0000000" +list1);
adapter = new Simpleadapter (//adapter fills the data, but here the data is empty
List
R.layout.lv02,
New string[]{"Biaoti"},
New int[]{r.id.stv00});
Slv.setadapter (adapter);
int totalheight = 0;
Get the total number of ListView items
i = 0; I < Adapter.getcount (); i++) {
View ListItem = Adapter.getview (i, NULL, SLV);
Listitem.measure (0, 0);
Totalheight + = Listitem.getmeasuredheight ();
}
Viewgroup.layoutparams params = Slv.getlayoutparams ();
Params.height = Totalheight + (slv.getdividerheight () * (Slv.getcount ()-1));
Slv.setlayoutparams (params); }
catch (Exception e)
{
System.out.println ("List1 anomaly");
}}}//in the mainactivity, the data is not displayed in the Ej.java, and the data is interrupted in Httpcon.java according to the SYSTEM.OUT.PRINTLN (). Initial data in Httpcon, to the last output when the data becomes empty?? But the same Imgurl data in the Mainactivity.java normal display, and change the other data in the Ej.java display also no problem?? Ask for advice Ah!!
Transfer data: Imgurl
/upload/comm/2010-05-26/eb6f19d7-34aa-495c-ba4a-7590297406ba.jpg
/upload/comm/2010-05-27/0e127bc1-84c9-40b6-9ef2-286672fdf51f.jpg
/upload/comm/2010-05-27/89927184-4c43-408a-90ad-ffdf4afaef65.jpg
/upload/comm/2010-05-27/d3030916-ff43-464c-97a3-71e5398af221.jpg
/upload/comm/2010-05-27/f3feee03-a12c-43f1-9eed-02a09a006521.jpg
/upload/comm/2010-05-27/e32ba156-c43c-4348-b2ca-0ad0318b5878.jpg
==================== Solution 1====================
Deserve, it's just that I have met this problem these days, you follow my 3 floor and 7 floor to write the changes, the program can run up. I have been able to run it correctly.
Troubled for weeks, ask Ah, Android and websevice data interaction very strange problem