我试图在async onPostExecute方法中显示我从EditText中的链接获得的一些文本 这是我的代码我发送一个GET请求获取JSON数组然后我将它转换为一个字符串,以便在EditText中显示它停止的问题(有例外)当我尝试将文本设置为编辑文本时:
import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
public class MyPage extends Activity {
Tools tools = new Tools() ;
String str ="" ;
//TextView txt = (TextView)findViewById(R.id.textView1) ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_page);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String name = extras.getString("name");
String pass = extras.getString("pass");
String url = "http://example.com/Andoid/getdata.php?"
+ "name=" + name + "&pass=" + pass;
GetData gd = new GetData() ;
gd.execute(url) ;
//txt.setText(str) ;
}
}
class GetData extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
HttpEntity httpEntity = null;
JSONArray jsonArry = null;
String data = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient(); // HttpClient
HttpGet httpGet = new HttpGet(params[0]);
HttpResponse httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Convert HttpEntity into JSON Array
if (httpEntity != null) {
try {
String entityResponse = EntityUtils.toString(httpEntity);
jsonArry = new JSONArray(entityResponse);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
data = tools.JsonGetData(jsonArry);
}
return data;
}
@Override
protected void onPostExecute(String result) {
EditText edttxt = (EditText) findViewById (R.id.editText3) ;
edttxt.setText(result ,TextView.BufferType.EDITABLE) ;
super.onPostExecute(result);
str = result ;
}
}
我调试了应用程序并在此行停止了一个例外:
edttxt.setText(result) ;
我不知道为什么以及如何解决它?
以下是LogCat的日志历史记录:
12-18 02:11:44.780: I/dalvikvm(4223): Debugger is active
12-18 02:11:44.810: I/System.out(4223): Debugger has connected
12-18 02:11:44.810: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.020: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.230: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.440: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.650: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.860: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.070: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.280: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.490: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.700: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.910: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:47.120: I/System.out(4223): debugger has settled (1430)
12-18 02:11:47.220: I/PGA(4223): New SOCKET connection: com.example.socialnetcit (pid 4223, tid 4223)
12-18 02:12:48.650: I/Choreographer(4223): Skipped 1816 frames! The application may be doing too much work on its main thread.
12-18 02:19:47.150: W/ActivityThread(4303): Application com.example.socialnetcit is waiting for the debugger on port 8100...
12-18 02:19:47.160: I/System.out(4303): Sending WAIT chunk
12-18 02:19:47.280: I/dalvikvm(4303): Debugger is active
12-18 02:19:47.370: I/System.out(4303): Debugger has connected
12-18 02:19:47.370: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:47.580: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:47.790: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.000: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.210: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.420: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.630: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.840: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.050: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.260: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.470: I/System.out(4303): debugger has settled (1420)
12-18 02:19:49.610: I/PGA(4303): New SOCKET connection: com.example.socialnetcit (pid 4303, tid 4303)
12-18 02:20:16.200: D/dalvikvm(4303): threadid=13: still suspended after undo (sc=1 dc=1)
12-18 02:20:18.390: D/dalvikvm(4303): threadid=13: still suspended after undo (sc=1 dc=1)
12-18 02:20:18.390: I/Choreographer(4303): Skipped 669 frames! The application may be doing too much work on its main thread.
12-18 02:21:24.760: D/AndroidRuntime(4303): Shutting down VM
12-18 02:21:24.760: W/dalvikvm(4303): threadid=1: thread exiting with uncaught exception (group=0x95d79b20)
12-18 02:21:24.760: D/AndroidRuntime(4303): procName from cmdline: com.example.socialnetcit
12-18 02:21:24.760: E/AndroidRuntime(4303): in writeCrashedAppName, pkgName :com.example.socialnetcit
12-18 02:21:24.760: D/AndroidRuntime(4303): file written successfully with content: com.example.socialnetcit StringBuffer : ;com.example.socialnetcit
12-18 02:21:24.760: W/FileUtils(4303): Failed to chmod(/data/data/.tmp/.crashed_app): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)
12-18 02:21:24.780: I/Process(4303): Sending signal. PID: 4303 SIG: 9
12-18 02:21:24.780: E/AndroidRuntime(4303): FATAL EXCEPTION: main
12-18 02:21:24.780: E/AndroidRuntime(4303): Process: com.example.socialnetcit, PID: 4303
12-18 02:21:24.780: E/AndroidRuntime(4303): java.lang.NullPointerException
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.example.socialnetcit.MyPage$GetData.onPostExecute(MyPage.java:84)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.example.socialnetcit.MyPage$GetData.onPostExecute(MyPage.java:1)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask.finish(AsyncTask.java:632)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.Handler.dispatchMessage(Handler.java:102)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.Looper.loop(Looper.java:136)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.app.ActivityThread.main(ActivityThread.java:5021)
12-18 02:21:24.780: E/AndroidRuntime(4303): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 02:21:24.780: E/AndroidRuntime(4303): at java.lang.reflect.Method.invoke(Method.java:515)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
12-18 02:21:24.780: E/AndroidRuntime(4303): at dalvik.system.NativeStart.main(Native Method)
我已将textedit3修改为现有的TextEdit,但我仍遇到新的例外问题:
12-18 02:11:44.780: I/dalvikvm(4223): Debugger is active
12-18 02:11:44.810: I/System.out(4223): Debugger has connected
12-18 02:11:44.810: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.020: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.230: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.440: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.650: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:45.860: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.070: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.280: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.490: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.700: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:46.910: I/System.out(4223): waiting for debugger to settle...
12-18 02:11:47.120: I/System.out(4223): debugger has settled (1430)
12-18 02:11:47.220: I/PGA(4223): New SOCKET connection: com.example.socialnetcit (pid 4223, tid 4223)
12-18 02:12:48.650: I/Choreographer(4223): Skipped 1816 frames! The application may be doing too much work on its main thread.
12-18 02:19:47.150: W/ActivityThread(4303): Application com.example.socialnetcit is waiting for the debugger on port 8100...
12-18 02:19:47.160: I/System.out(4303): Sending WAIT chunk
12-18 02:19:47.280: I/dalvikvm(4303): Debugger is active
12-18 02:19:47.370: I/System.out(4303): Debugger has connected
12-18 02:19:47.370: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:47.580: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:47.790: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.000: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.210: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.420: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.630: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:48.840: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.050: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.260: I/System.out(4303): waiting for debugger to settle...
12-18 02:19:49.470: I/System.out(4303): debugger has settled (1420)
12-18 02:19:49.610: I/PGA(4303): New SOCKET connection: com.example.socialnetcit (pid 4303, tid 4303)
12-18 02:20:16.200: D/dalvikvm(4303): threadid=13: still suspended after undo (sc=1 dc=1)
12-18 02:20:18.390: D/dalvikvm(4303): threadid=13: still suspended after undo (sc=1 dc=1)
12-18 02:20:18.390: I/Choreographer(4303): Skipped 669 frames! The application may be doing too much work on its main thread.
12-18 02:21:24.760: D/AndroidRuntime(4303): Shutting down VM
12-18 02:21:24.760: W/dalvikvm(4303): threadid=1: thread exiting with uncaught exception (group=0x95d79b20)
12-18 02:21:24.760: D/AndroidRuntime(4303): procName from cmdline: com.example.socialnetcit
12-18 02:21:24.760: E/AndroidRuntime(4303): in writeCrashedAppName, pkgName :com.example.socialnetcit
12-18 02:21:24.760: D/AndroidRuntime(4303): file written successfully with content: com.example.socialnetcit StringBuffer : ;com.example.socialnetcit
12-18 02:21:24.760: W/FileUtils(4303): Failed to chmod(/data/data/.tmp/.crashed_app): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)
12-18 02:21:24.780: I/Process(4303): Sending signal. PID: 4303 SIG: 9
12-18 02:21:24.780: E/AndroidRuntime(4303): FATAL EXCEPTION: main
12-18 02:21:24.780: E/AndroidRuntime(4303): Process: com.example.socialnetcit, PID: 4303
12-18 02:21:24.780: E/AndroidRuntime(4303): java.lang.NullPointerException
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.example.socialnetcit.MyPage$GetData.onPostExecute(MyPage.java:84)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.example.socialnetcit.MyPage$GetData.onPostExecute(MyPage.java:1)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask.finish(AsyncTask.java:632)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask.access$600(AsyncTask.java:177)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.Handler.dispatchMessage(Handler.java:102)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.os.Looper.loop(Looper.java:136)
12-18 02:21:24.780: E/AndroidRuntime(4303): at android.app.ActivityThread.main(ActivityThread.java:5021)
12-18 02:21:24.780: E/AndroidRuntime(4303): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 02:21:24.780: E/AndroidRuntime(4303): at java.lang.reflect.Method.invoke(Method.java:515)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
12-18 02:21:24.780: E/AndroidRuntime(4303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
12-18 02:21:24.780: E/AndroidRuntime(4303): at dalvik.system.NativeStart.main(Native Method)
12-18 02:41:20.480: W/ActivityThread(4502): Application com.example.socialnetcit is waiting for the debugger on port 8100...
12-18 02:41:20.490: I/System.out(4502): Sending WAIT chunk
12-18 02:41:23.690: I/dalvikvm(4502): Debugger is active
12-18 02:41:23.850: I/System.out(4502): Debugger has connected
12-18 02:41:23.850: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:24.060: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:24.270: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:24.480: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:24.690: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:24.900: I/System.out(4502): waiting for debugger to settle...
12-18 02:41:25.110: I/System.out(4502): debugger has settled (1310)
12-18 02:41:25.250: I/PGA(4502): New SOCKET connection: com.example.socialnetcit (pid 4502, tid 4502)