2012-06-10 114 views
4

有誰知道我能做些什麼來使JDBC連接在Android 4.0上工作。它在Android 1.6-2.3上運行良好。我用戴夫克拉默的構建: http://groups.google.com/group/pgandroid/browse_thread/thread/d8b400f039f66d5f/f77b2e2a99370a36?lnk=raot#f77b2e2a99370a36Android 4.0上的PostgreSQL JDBC連接失敗

的logcat的說:

06-10 17:35:51.043: E/AndroidRuntime(798): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.belonogov.connectjdbc/com.belonogov.connectjdbc.ConnectJDBCActivity}: java.lang.NullPointerException 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread.access$600(ActivityThread.java:123) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.os.Handler.dispatchMessage(Handler.java:99) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.os.Looper.loop(Looper.java:137) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread.main(ActivityThread.java:4424) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at java.lang.reflect.Method.invokeNative(Native Method) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at java.lang.reflect.Method.invoke(Method.java:511) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at dalvik.system.NativeStart.main(Native Method) 
06-10 17:35:51.043: E/AndroidRuntime(798): Caused by: java.lang.NullPointerException 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at com.belonogov.connectjdbc.ConnectJDBCActivity$CustomDrawableView.<init>(ConnectJDBCActivity.java:81) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at com.belonogov.connectjdbc.ConnectJDBCActivity.onCreate(ConnectJDBCActivity.java:27) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.Activity.performCreate(Activity.java:4465) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
06-10 17:35:51.043: E/AndroidRuntime(798): 
... 11 more 

這只是一個簡單的應用程序連接到數據庫。

+0

你會找到答案[這裏](http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception)。你必須使用[AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html)。 – mikek

回答

0

最有可能你會在這裏找到答案:

06-10 17:35:51.043: E/AndroidRuntime(798): Caused by: java.lang.NullPointerException 
06-10 17:35:51.043: E/AndroidRuntime(798):  at com.belonogov.connectjdbc.ConnectJDBCActivity$CustomDrawableView.<init>(ConnectJDBCActivity.java:81) 
06-10 17:35:51.043: E/AndroidRuntime(798):  at com.belonogov.connectjdbc.ConnectJDBCActivity.onCreate(ConnectJDBCActivity.java:27) 

這意味着:查找類ConnectJDBCActivity.java,線81和尋找什麼參考可能是null

+0

謝謝你的回答,是的,我知道。這些行如:st = connection.createStatement(); rs = st.executeQuery(query); rs.next();給NullPointerException。但它適用於較舊版本的Android。我能做些什麼嗎? – sashabelonogov