模拟器抛出错误消息
不幸的是,Helloworld已经停止了
调试日志信息
10-23 06:21:00.575: E/(5090): test 1
10-23 06:21:00.665: E/(5090): test 2
10-23 06:21:00.665: E/(5090): test 3
10-23 06:21:00.665: E/(5090): main
10-23 06:21:00.686: E/(5090): ==[id=01, message= main]
10-23 06:21:00.866: D/dalvikvm(5090): GC_FOR_ALLOC freed 148K, 9% free 2870K/3136K, paused 37ms, total 50ms
10-23 06:21:00.918: D/AndroidRuntime(5090): Shutting down VM
10-23 06:21:00.918: W/dalvikvm(5090): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
10-23 06:21:00.976: E/AndroidRuntime(5090): FATAL EXCEPTION: main
10-23 06:21:00.976: E/AndroidRuntime(5090): java.lang.IllegalStateException: Could not execute method of the activity
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.view.View$1.onClick(View.java:3633)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.view.View.performClick(View.java:4240)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.view.View$PerformClick.run(View.java:17721)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.os.Handler.handleCallback(Handler.java:730)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.os.Handler.dispatchMessage(Handler.java:92)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.os.Looper.loop(Looper.java:137)
10-23 06:21:00.976: E/AndroidRuntime(5090): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-23 06:21:00.976: E/AndroidRuntime(5090): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 06:21:00.976: E/AndroidRuntime(5090): at java.lang.reflect.Method.invoke(Method.java:525)
10-23 06:21:00.976: E/AndroidRuntime(5090): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-23 06:21:00.976: E/AndroidRuntime(5090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-23 06:21:00.976: E/AndroidRuntime(5090): at dalvik.system.NativeStart.main(Native Method)
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myandroid.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
JAVA
Log.e(TAG, "test 1");
//log.debug("test 1");
// output.setText("this is my tesing"+GroupAll);
System.out.print("test");
//check whether the msg empty or not
if(GroupAll.length()>0) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.8.15:8085/mobile/save.php?device=system");
Log.e(TAG, "test 2");
try {Log.e(TAG, "test 3");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "01"));
nameValuePairs.add(new BasicNameValuePair("message", GroupAll));
Log.e(TAG, GroupAll);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.e(TAG, "=="+nameValuePairs);
httpclient.execute(httppost);
GroupAll = "";
// msgTextField.set.setText(""); //reset the message text field
Toast.makeText(getBaseContext(),"Sent",Toast.LENGTH_SHORT).show();
如果我从清单中删除以下代码段,
我的错误
10-23 07:01:14.236: E/(8071): test 1
10-23 07:01:14.406: E/(8071): test 2
10-23 07:01:14.406: E/(8071): test 3
10-23 07:01:14.406: E/(8071): main
10-23 07:01:14.455: E/(8071): ==[id=01, message= main]
10-23 07:01:14.705: D/dalvikvm(8071): GC_FOR_ALLOC freed 152K, 9% free 2866K/3136K, paused 37ms, total 52ms
10-23 07:01:14.726: W/System.err(8071): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.8.15:8085 refused
10-23 07:01:14.755: W/System.err(8071): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
10-23 07:01:14.755: W/System.err(8071): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
答案 0 :(得分:0)
添加
<uses-permission android:name="android.permission.INTERNET"/>
到你的清单
使用不同的线程进行http连接。检查AsyncTask是否正确。无论如何,我不确定这是你唯一的问题