单击列表视图的项目时出错

时间:2013-01-28 19:14:39

标签: android

我是android的新手,我正在开发一个应用程序,它生成一个mysq查询并返回数据,我解释得更好,我有第一个屏幕,其中一个名称例如收入,并发送给彼得的基础上,如果找到返回名称和名字在屏幕上显示另一个在列表视图到目前为止很好,问题是,当我点击这个名称应该显示另一个屏幕,这也应该显示这个人的所有数据应该显示姓氏cedula等...但q通过点击给我一个错误,这是我得到logcat的错误

01-17 16:03:49.590: E/AndroidRuntime(1072): FATAL EXCEPTION: main
01-17 16:03:49.590: E/AndroidRuntime(1072): android.os.NetworkOnMainThreadException
01-17 16:03:49.590: E/AndroidRuntime(1072): at android.os.StrictMode$AndroidBlockGuardPolicy.onNe twork(StrictMode.java:1117)
01-17 16:03:49.590: E/AndroidRuntime(1072): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java: 84)
01-17 16:03:49.590: E/AndroidRuntime(1072): at libcore.io.IoBridge.connectErrno(IoBridge.java:127 )
01-17 16:03:49.590: E/AndroidRuntime(1072): at libcore.io.IoBridge.connect(IoBridge.java:112)
01-17 16:03:49.590: E/AndroidRuntime(1072): at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:192)
01-17 16:03:49.590: E/AndroidRuntime(1072): at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:459)
01-17 16:03:49.590: E/AndroidRuntime(1072): at java.net.Socket.connect(Socket.java:842)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.conn.scheme.PlainSocketFactory.con nectSocket(PlainSocketFactory.java:119)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.conn.DefaultClientConnectionO perator.openConnection(DefaultClientConnectionOper ator.java:144)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.conn.AbstractPoolEntry.open(A bstractPoolEntry.java:164)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.conn.AbstractPooledConnAdapte r.open(AbstractPooledConnAdapter.java:119)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.client.DefaultRequestDirector .execute(DefaultRequestDirector.java:360)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.client.AbstractHttpClient.exe cute(AbstractHttpClient.java:555)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.client.AbstractHttpClient.exe cute(AbstractHttpClient.java:487)
01-17 16:03:49.590: E/AndroidRuntime(1072): at org.apache.http.impl.client.AbstractHttpClient.exe cute(AbstractHttpClient.java:465)
01-17 16:03:49.590: E/AndroidRuntime(1072): at com.example.taller06oct.JSONParser.makeHttpRequest (JSONParser.java:62)
01-17 16:03:49.590: E/AndroidRuntime(1072): at com.example.taller06oct.EditEmpleadosActivity$GetE mpleadoDetails$1.run(EditEmpleadosActivity.java:13 4)
01-17 16:03:49.590: E/AndroidRuntime(1072): at android.os.Handler.handleCallback(Handler.java:725 )
01-17 16:03:49.590: E/AndroidRuntime(1072): at android.os.Handler.dispatchMessage(Handler.java:92 )
01-17 16:03:49.590: E/AndroidRuntime(1072): at android.os.Looper.loop(Looper.java:137)
01-17 16:03:49.590: E/AndroidRuntime(1072): at android.app.ActivityThread.main(ActivityThread.jav a:5039)
01-17 16:03:49.590: E/AndroidRuntime(1072): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 16:03:49.590: E/AndroidRuntime(1072): at java.lang.reflect.Method.invoke(Method.java:511)
01-17 16:03:49.590: E/AndroidRuntime(1072): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:793)
01-17 16:03:49.590: E/AndroidRuntime(1072): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:560)
01-17 16:03:49.590: E/AndroidRuntime(1072): at dalvik.system.NativeStart.main(Native Method)

我正在审核,显然问题出现在转换q json中,但正如我所说我是java新手并且android不懂如何解决它,我留下我的Java代码,顺便说一下我使用AsyncTask会提到......

try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cedula", cedula));
Log.i("1","busca empleado para cargar detalles");
// getting Empleado details by making HTTP request
// Note that Empleado details url will use GET request
**JSONObject json = jsonParser.makeHttpRequest(
url_detalles_empleado, "GET", params);**
Log.i("1","llama a php busqueda");

// check your log for json response
Log.d("Single Empleado Details", json.toString());

// json success tag
success = json.getInt(TAG_SUCCESS);

提前致谢,我希望你的帮助谢谢......

1 个答案:

答案 0 :(得分:2)

您无法在主线程中执行网络操作。

Checkout AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html

用于无痛穿线。