无法在调试设备中使用JSON将android应用程序连接到PHP mysql数据库[应用程序已在avd中连接]

时间:2014-03-02 13:12:22

标签: php android mysql json

我正在尝试学习如何使用JSON将我的Android应用程序连接到PHP mysql数据库。所以我从this网站导入了该项目。数据库存在于localhost中。记录已插入到数据库,当我使用以下服务器地址在avd中运行代码时:

http://10.0.2.2:8080/

但在我大学的演讲期间,我将不得不用标签/电话显示它。我尝试了以下内容,以便应用程序开始工作:

1)在我的手机中启动了2G / 3G,通过热点将笔记本电脑连接到我的手机上。 2)使用USB线将我的手机连接到我的笔记本电脑(这是由学院的一位老年人建议的) 3)将服务器地址更改为移动设备创建的网络的IP地址。

当我们尝试添加记录或查看记录时,应用程序崩溃。

此外,我在笔记本电脑上运行了IIS和WAMP,因为我手动将WAMP配置为8080端口。

如果数据库位于localhost中,请告诉我如何在设备中运行此应用。在一台笔记本电脑上安装IIS和WAMP会产生这样的问题吗?

修改

logcat的

03-02 18:49:16.796: W/ApplicationPackageManager(20675): getCSCPackageItemText()
03-02 18:49:34.621: D/ProgressBar(20675): updateDrawableBounds: left = 0
03-02 18:49:34.621: D/ProgressBar(20675): updateDrawableBounds: top = 0
03-02 18:49:34.621: D/ProgressBar(20675): updateDrawableBounds: right = 144
03-02 18:49:34.621: D/ProgressBar(20675): updateDrawableBounds: bottom = 144
03-02 18:50:37.896: I/System.out(20675): AsyncTask #1 calls detatch()
03-02 18:50:37.896: W/System.err(20675): org.apache.http.conn.HttpHostConnectException: Connection to http://192.168.43.77:8080 refused
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:212)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:167)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1179)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:644)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-02 18:50:37.901: W/System.err(20675):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
03-02 18:50:37.906: W/System.err(20675):    at com.example.androidhive.JSONParser.makeHttpRequest(JSONParser.java:51)
03-02 18:50:37.906: W/System.err(20675):    at com.example.androidhive.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:95)
03-02 18:50:37.906: W/System.err(20675):    at com.example.androidhive.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:1)
03-02 18:50:37.906: W/System.err(20675):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-02 18:50:37.906: W/System.err(20675):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-02 18:50:37.911: W/System.err(20675):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-02 18:50:37.911: W/System.err(20675):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-02 18:50:37.911: W/System.err(20675):    at java.lang.Thread.run(Thread.java:841)
03-02 18:50:37.911: W/System.err(20675): Caused by: java.net.ConnectException: failed to connect to /192.168.43.77 (port 8080): connect failed: ETIMEDOUT (Connection timed out)
03-02 18:50:37.916: W/System.err(20675):    at libcore.io.IoBridge.connect(IoBridge.java:114)
03-02 18:50:37.916: W/System.err(20675):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
03-02 18:50:37.916: W/System.err(20675):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
03-02 18:50:37.916: W/System.err(20675):    at java.net.Socket.connect(Socket.java:843)
03-02 18:50:37.916: W/System.err(20675):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
03-02 18:50:37.921: W/System.err(20675):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
03-02 18:50:37.921: W/System.err(20675):    ... 15 more
03-02 18:50:37.921: W/System.err(20675): Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
03-02 18:50:37.926: W/System.err(20675):    at libcore.io.Posix.connect(Native Method)
03-02 18:50:37.926: W/System.err(20675):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
03-02 18:50:37.926: W/System.err(20675):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
03-02 18:50:37.931: W/System.err(20675):    at libcore.io.IoBridge.connect(IoBridge.java:112)
03-02 18:50:37.931: W/System.err(20675):    ... 20 more
03-02 18:50:37.931: E/Buffer Error(20675): Error converting result java.lang.NullPointerException: lock == null
03-02 18:50:37.931: E/JSON Parser(20675): Error parsing data org.json.JSONException: End of input at character 0 of 
03-02 18:50:37.936: W/dalvikvm(20675): threadid=11: thread exiting with uncaught exception (group=0x41814c08)
03-02 18:50:37.951: E/AndroidRuntime(20675): FATAL EXCEPTION: AsyncTask #1
03-02 18:50:37.951: E/AndroidRuntime(20675): Process: com.example.androidhive, PID: 20675
03-02 18:50:37.951: E/AndroidRuntime(20675): java.lang.RuntimeException: An error occured while executing doInBackground()
03-02 18:50:37.951: E/AndroidRuntime(20675):    at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.lang.Thread.run(Thread.java:841)
03-02 18:50:37.951: E/AndroidRuntime(20675): Caused by: java.lang.NullPointerException
03-02 18:50:37.951: E/AndroidRuntime(20675):    at com.example.androidhive.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:99)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at com.example.androidhive.NewProductActivity$CreateNewProduct.doInBackground(NewProductActivity.java:1)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-02 18:50:37.951: E/AndroidRuntime(20675):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-02 18:50:37.951: E/AndroidRuntime(20675):    ... 3 more
03-02 18:50:38.301: E/WindowManager(20675): android.view.WindowLeaked: Activity com.example.androidhive.NewProductActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42a91230 V.E..... R.....I. 0,0-655,346} that was originally added here
03-02 18:50:38.301: E/WindowManager(20675):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:456)
03-02 18:50:38.301: E/WindowManager(20675):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:267)
03-02 18:50:38.301: E/WindowManager(20675):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
03-02 18:50:38.301: E/WindowManager(20675):     at android.app.Dialog.show(Dialog.java:288)
03-02 18:50:38.301: E/WindowManager(20675):     at com.example.androidhive.NewProductActivity$CreateNewProduct.onPreExecute(NewProductActivity.java:76)
03-02 18:50:38.301: E/WindowManager(20675):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
03-02 18:50:38.301: E/WindowManager(20675):     at android.os.AsyncTask.execute(AsyncTask.java:535)
03-02 18:50:38.301: E/WindowManager(20675):     at com.example.androidhive.NewProductActivity$1.onClick(NewProductActivity.java:56)
03-02 18:50:38.301: E/WindowManager(20675):     at android.view.View.performClick(View.java:4633)
03-02 18:50:38.301: E/WindowManager(20675):     at android.view.View$PerformClick.run(View.java:19330)
03-02 18:50:38.301: E/WindowManager(20675):     at android.os.Handler.handleCallback(Handler.java:733)
03-02 18:50:38.301: E/WindowManager(20675):     at android.os.Handler.dispatchMessage(Handler.java:95)
03-02 18:50:38.301: E/WindowManager(20675):     at android.os.Looper.loop(Looper.java:157)
03-02 18:50:38.301: E/WindowManager(20675):     at android.app.ActivityThread.main(ActivityThread.java:5356)
03-02 18:50:38.301: E/WindowManager(20675):     at java.lang.reflect.Method.invokeNative(Native Method)
03-02 18:50:38.301: E/WindowManager(20675):     at java.lang.reflect.Method.invoke(Method.java:515)
03-02 18:50:38.301: E/WindowManager(20675):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-02 18:50:38.301: E/WindowManager(20675):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-02 18:50:38.301: E/WindowManager(20675):     at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案