我正在尝试我的第一个GAE服务器和Android连接。我在我的计算机上通过Android ADT运行GAE服务器(192.168.1.24)。我的Android设备通过USB以开发人员模式连接。我正在尝试从设备发出HTTP请求并存储响应。但我得到以下错误。
02-23 03:10:22.915: E/AndroidRuntime(18076): FATAL EXCEPTION: main
02-23 03:10:22.915: E/AndroidRuntime(18076): java.lang.IllegalStateException: Could not execute method of the activity
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$1.onClick(View.java:3838)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View.performClick(View.java:4475)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$PerformClick.run(View.java:18796)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Handler.handleCallback(Handler.java:730)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Handler.dispatchMessage(Handler.java:92)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.os.Looper.loop(Looper.java:137)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.app.ActivityThread.main(ActivityThread.java:5455)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invoke(Method.java:525)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
02-23 03:10:22.915: E/AndroidRuntime(18076): at dalvik.system.NativeStart.main(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): Caused by: java.lang.reflect.InvocationTargetException
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.lang.reflect.Method.invoke(Method.java:525)
02-23 03:10:22.915: E/AndroidRuntime(18076): at android.view.View$1.onClick(View.java:3833)
02-23 03:10:22.915: E/AndroidRuntime(18076): ... 11 more
02-23 03:10:22.915: E/AndroidRuntime(18076): Caused by: java.lang.IllegalArgumentException: Illegal character in scheme at index 0: 192.168.1.24:8889/myserver?username=qwerty&password=qwerty
02-23 03:10:22.915: E/AndroidRuntime(18076): at java.net.URI.create(URI.java:727)
02-23 03:10:22.915: E/AndroidRuntime(18076): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
02-23 03:10:22.915: E/AndroidRuntime(18076): at httprequest.GetMethods.doGetWithResponse(GetMethods.java:28)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.example.tandemstory.UserAuth.doAuth(UserAuth.java:24)
02-23 03:10:22.915: E/AndroidRuntime(18076): at com.example.tandemstory.SignIn.onSignin(SignIn.java:74)
02-23 03:10:22.915: E/AndroidRuntime(18076): ... 14 more
从Android设备发起http请求的声明如下。
String alias=UserAuth.doAuth(username, password);
UserAuth.doAuth()如下所示
public static String doAuth(String username,String password) {
// CONSTRUCT GET REQUEST URL
String url = "192.168.1.24/myserver?username=qwerty&password=qwerty"
// XML RESPONSE AS A STRING GETS RETURNED
String response = GetMethods.doGetWithResponse(URL_BASE, httpClient);
return response;
}
GetMethods.doGetWithResponse()如下所示
public static String doGetWithResponse(String mUrl,DefaultHttpClient httpClient){
String ret=null;
HttpResponse response=null;
//initiate get method with username and password
HttpGet getMethod=new HttpGet(mUrl);
try{
//use http client to execute method
response=httpClient.execute(getMethod);
if(response!=null){
//convert http response to string
ret=getResponseBody(response);
}
}catch(Exception e){
e.printStackTrace();
}
return ret;
}
请指出解决方案。
答案 0 :(得分:0)
异常java.lang.IllegalArgumentException: Illegal character in scheme at index 0: 192.168.1.24:8889/myserver?username=qwerty&password=qwerty
似乎表明可以通过尝试以下方法来解决问题:
http://
,并查看是否有效。http://
前缀,并正确编码网址。