|
|
|
ขอถามเรื่องการ ใช้ android เพือ connect กับ web service หน่อยครับ |
|
|
|
|
|
|
|
จากลิ้งค์ ผมทำตามลิ๋งนี้แล้วมันดึงข้อมูลมาลง android ไม่ได้ครับ
มัน error ตามนี้ครับ
Code
05-08 16:58:55.189: W/System.err(7020): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG (empty) <br>@1:6 in java.io.InputStreamReader@406d5ae0)
05-08 16:58:55.189: W/System.err(7020): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
05-08 16:58:55.189: W/System.err(7020): at org.kxml2.io.KXmlParser.require(KXmlParser.java:1424)
05-08 16:58:55.199: W/System.err(7020): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
05-08 16:58:55.199: W/System.err(7020): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
05-08 16:58:55.199: W/System.err(7020): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
05-08 16:58:55.199: W/System.err(7020): at app.dbd_app.DBD_C_SEARCH$1.onClick(DBD_C_SEARCH.java:83)
05-08 16:58:55.199: W/System.err(7020): at android.view.View.performClick(View.java:2485)
05-08 16:58:55.199: W/System.err(7020): at android.view.View$PerformClick.run(View.java:9080)
05-08 16:58:55.209: W/System.err(7020): at android.os.Handler.handleCallback(Handler.java:587)
05-08 16:58:55.209: W/System.err(7020): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 16:58:55.209: W/System.err(7020): at android.os.Looper.loop(Looper.java:130)
05-08 16:58:55.209: W/System.err(7020): at android.app.ActivityThread.main(ActivityThread.java:3768)
05-08 16:58:55.209: W/System.err(7020): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:58:55.209: W/System.err(7020): at java.lang.reflect.Method.invoke(Method.java:507)
05-08 16:58:55.209: W/System.err(7020): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
05-08 16:58:55.209: W/System.err(7020): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
05-08 16:58:55.219: W/System.err(7020): at dalvik.system.NativeStart.main(Native Method)
05-08 16:59:12.729: W/IInputConnectionWrapper(7020): showStatusIcon on inactive InputConnection
อันนี้ code ผมครับ
Code (Android-Java)
package app.dbd_app;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
public class DBD_C_SEARCH extends Activity {
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dbd_page_search);
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// btnSearch
Button btnSearch = (Button) this.findViewById(R.id.DBD_BTD_SEARCH);
btnSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// txtKeySearch
EditText txtKeySearch = (EditText) findViewById(R.id.DBD_ET_SEARCH_NUM);
// Disbled Keyboard auto focus
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtKeySearch.getWindowToken(), 0);
// listView1
final ListView lisView1 = (ListView)findViewById(R.id.DBD_LIST_FOR_SEARCH);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("mid", txtKeySearch.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
if (result != null) {
Toast.makeText(getApplicationContext(),
"Web ssssss not Response!", Toast.LENGTH_LONG)
.show();
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
JSONArray data = new JSONArray(result.getProperty(0).toString());
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("CustomerID", c.getString("g_id"));
map.put("Name", c.getString("g_name"));
map.put("Email", c.getString("g_price"));
MyArrList.add(map);
}
SimpleAdapter sAdap;
sAdap = new SimpleAdapter(DBD_C_SEARCH.this, MyArrList, R.layout.dbd_column_search,
new String[] {"CustomerID", "Name", "Email"}, new int[] {R.id.DBD_COLUMN_IDMEMBER, R.id.DBD_COLUMN_NAMEMEMBER, R.id.DBD_COLUMN_SNAMEMEMBER});
lisView1.setAdapter(sAdap);
} else {
Toast.makeText(getApplicationContext(),
"Web Service not Response!", Toast.LENGTH_LONG)
.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
Tag : Mobile
|
ประวัติการแก้ไข 2013-05-08 17:01:04 2013-05-09 10:17:58
|
|
|
|
|
Date :
2013-05-08 16:37:44 |
By :
makachol |
View :
1594 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เหมือนกับว่ามันส่งค่ากลับมาไม่ถูกตาม Format ที่คุณต้องการน่ะครับ
Android Get Result / Search Data from Server via Web Service
|
|
|
|
|
Date :
2013-05-09 06:37:32 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วต้องเช็ดยังงัยครับ
|
|
|
|
|
Date :
2013-05-09 09:53:22 |
By :
makachol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณอาจจะต้องใช้การ Debug ดูครับ
|
|
|
|
|
Date :
2013-05-09 12:25:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลอง debug แล้ว ครับ มันวิ่งมาหยุดที่ตรงง
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
ประมานนี้ครับ แล้วมันก็ออก มาที่ cath แล้วก็หลุดเลยครับ
|
|
|
|
|
Date :
2013-05-09 13:47:57 |
By :
makachol |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|