2013-04-28 74 views
0

我想創建一個應用程序與MySQL的Android連接。但該應用突然停止。我不明白是什麼導致了這個問題。我在之前的問題中詢問過同樣的問題。請幫助。我很絕望。這是對我的學術項目我想用mysql的android連接創建一個應用程序。但該應用程序突然停止

誤差

04-28 15:43:29.918: D/dalvikvm(8036): Late-enabling CheckJNI 
04-28 15:43:30.278: D/dalvikvm(8036): GC_FOR_ALLOC freed 78K, 12% free 9560K/10759K, paused 33ms, total 33ms 
04-28 15:43:30.288: I/dalvikvm-heap(8036): Grow heap (frag case) to 10.705MB for 437672-byte allocation 
04-28 15:43:30.358: D/dalvikvm(8036): GC_CONCURRENT freed <1K, 11% free 9986K/11207K, paused 13ms+7ms, total 70ms 
04-28 15:43:30.358: D/dalvikvm(8036): WAIT_FOR_CONCURRENT_GC blocked 55ms 
04-28 15:43:30.449: D/dalvikvm(8036): GC_FOR_ALLOC freed 2K, 11% free 10211K/11463K, paused 56ms, total 57ms 
04-28 15:43:30.649: D/libEGL(8036): loaded /system/lib/egl/libEGL_mali.so 
04-28 15:43:30.759: D/libEGL(8036): loaded /system/lib/egl/libGLESv1_CM_mali.so 
04-28 15:43:30.789: D/libEGL(8036): loaded /system/lib/egl/libGLESv2_mali.so 
04-28 15:43:30.879: D/OpenGLRenderer(8036): Enabling debug mode 0 
04-28 15:43:32.130: D/dalvikvm(8036): GC_CONCURRENT freed 11K, 9% free 10906K/11975K, paused 4ms+6ms, total 56ms 
04-28 15:43:32.130: D/dalvikvm(8036): WAIT_FOR_CONCURRENT_GC blocked 31ms 
04-28 15:43:32.200: D/dalvikvm(8036): GC_FOR_ALLOC freed <1K, 10% free 11335K/12487K, paused 47ms, total 47ms 
04-28 15:43:32.290: D/dalvikvm(8036): GC_CONCURRENT freed 3K, 8% free 11992K/12999K, paused 3ms+13ms, total 71ms 
04-28 15:43:32.681: E/SpannableStringBuilder(8036): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
04-28 15:43:32.681: E/SpannableStringBuilder(8036): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
04-28 15:43:34.422: E/SpannableStringBuilder(8036): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
04-28 15:43:34.422: E/SpannableStringBuilder(8036): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 
04-28 15:43:35.994: D/ProgressBar(8036): setProgress = 0 
04-28 15:43:35.994: D/ProgressBar(8036): setProgress = 0, fromUser = false 
04-28 15:43:35.994: D/ProgressBar(8036): mProgress = 0mIndeterminate = false, mMin = 0, mMax = 10000 
04-28 15:43:36.124: W/ResourceType(8036): Failure getting entry for 0x010802c8 (t=7 e=712) in package 0 (error -75) 
04-28 15:43:36.474: D/AndroidRuntime(8036): Shutting down VM 
04-28 15:43:36.474: W/dalvikvm(8036): threadid=1: thread exiting with uncaught exception (group=0x41a162a0) 
04-28 15:43:36.534: E/AndroidRuntime(8036): FATAL EXCEPTION: main 
04-28 15:43:36.534: E/AndroidRuntime(8036): android.os.NetworkOnMainThreadException 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at java.net.InetAddress.getAllByName(InetAddress.java:214) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at com.mahavega.qcdemo.JSONParser.makeHttpRequest(JSONParser.java:62) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at com.mahavega.qcdemo.MainActivity$GetEventDetails$1.run(MainActivity.java:198) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at android.os.Handler.handleCallback(Handler.java:615) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at android.os.Handler.dispatchMessage(Handler.java:92) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at android.os.Looper.loop(Looper.java:137) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at android.app.ActivityThread.main(ActivityThread.java:4856) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at java.lang.reflect.Method.invoke(Method.java:511) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) 
04-28 15:43:36.534: E/AndroidRuntime(8036):  at dalvik.system.NativeStart.main(Native Method) 
+0

請提供源代碼。 – MDMalik 2013-04-28 10:29:00

+0

你在你的模擬器和項目中使用哪個android版本? – ACengiz 2013-04-28 10:29:52

+0

http://stackoverflow.com/questions/16259430/connecting-android-to-mysql-database-application-ends – 2013-04-28 16:41:27

回答

2

的問題是,你正在努力讓自己在「主」線程的Android不會允許網絡連接。 嘗試使用AsyncTask。

0

從你的日誌看來,你似乎試圖在主線程上執行緩慢的網絡操作,因爲這會阻止用戶界面,應用程序不會響應。

嘗試做你正在使用doInBackground()

0

雖然它是一個學術項目在後臺做什麼東西,你不應該從客戶端應用程序訪問遠程SQL數據庫。這是不安全的,特別是在java/android中。

在應用程序和遠程數據庫之間創建一個很好的REST web服務層。所以你可以在服務器端消毒用戶輸入,因爲所有的用戶輸入是每個定義邪惡:)

,因爲我解釋logcat你已經使用web服務。異常真的很明顯的錯誤:NetworkOnMainThreadException

1

我想我找到了它。可能你的android版本是android 4.0及以上版本,你試圖在你的主線程上執行網絡操作。但是Android 4.0及以上版本不允許此操作,因爲您不允許通過網絡操作中斷應用程序的主線程。您應該在AsyncTask中執行您的網絡操作。希望這可以幫助。

相關問題