0

我是 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);

在此先感谢,希望您的帮助谢谢..

4

1 回答 1

2

您不能在主线程中进行网络操作。

结帐 AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html

用于无痛穿线。

于 2013-01-28T19:17:02.790 回答