2013-11-26 30 views
0

我有一個應用程序,在Android 4.x平穩運行,但不是在android 2.x.
我想要做的是從Web服務獲取一些信息並存儲在數據庫中。 我該怎麼辦? 這是產生錯誤代碼:我的android數據庫應用程序不工作在android 2.x

public String CallMethod(String methodName,ArrayList<ServiceParam> paramList) { 
     String result = "default"; 
     SoapObject request = new SoapObject(namespace, methodName); 
     PropertyInfo pi = new PropertyInfo(); 

     for(int i=0;i<paramList.size();i++){ 
      ServiceParam serviceParam; 
      serviceParam = paramList.get(i); 
      pi = new PropertyInfo(); 
      pi.setName(serviceParam.name); 
      pi.setValue(serviceParam.value); 
      pi.setType(serviceParam.type); 
      request.addProperty(pi); 
     } 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; 
     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(url); 
     try { 
      androidHttpTransport.call(namespace+methodName, envelope); 
      SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); 
      result= response.toString(); 
      output = result; 

     } catch (Exception e) { 
      Log.d("Ehsan", e.getMessage()); 
      Log.d("Ehsan", e.getLocalizedMessage()); 
      e.printStackTrace(); 
     } 

     return result; 
    } 

產生錯誤的路線是這樣的:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 

這是我的日誌貓:

11-26 11:26:02.666: W/SQLiteCompiledSql(12820): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT * FROM settings WHERE name='PersonId' 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at ClassLibrary.DbHelper.select(DbHelper.java:105) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at com.example.shareholders.entities.Settings.select(Settings.java:93) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at com.example.shareholders.entities.Settings.getValue(Settings.java:56) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at com.example.shareholders.Login.onCreate(Login.java:24) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.os.Looper.loop(Looper.java:123) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at java.lang.reflect.Method.invoke(Method.java:521) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
11-26 11:26:02.666: W/SQLiteCompiledSql(12820):  at dalvik.system.NativeStart.main(Native Method) 
11-26 11:26:02.736: E/Database(12820): close() was never explicitly called on database '/data/data/com.example.shareholders/databases/shareholders.db' 
11-26 11:26:02.736: E/Database(12820): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810) 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817) 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851) 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844) 
11-26 11:26:02.736: E/Database(12820): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540) 
11-26 11:26:02.736: E/Database(12820): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203) 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98) 
11-26 11:26:02.736: E/Database(12820): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158) 
11-26 11:26:02.736: E/Database(12820): at ClassLibrary.DbHelper.select(DbHelper.java:99) 
11-26 11:26:02.736: E/Database(12820): at com.example.shareholders.entities.Settings.select(Settings.java:93) 
11-26 11:26:02.736: E/Database(12820): at com.example.shareholders.entities.Settings.getValue(Settings.java:56) 
11-26 11:26:02.736: E/Database(12820): at com.example.shareholders.Login.onCreate(Login.java:24) 
11-26 11:26:02.736: E/Database(12820): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
11-26 11:26:02.736: E/Database(12820): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
11-26 11:26:02.736: E/Database(12820): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
11-26 11:26:02.736: E/Database(12820): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
11-26 11:26:02.736: E/Database(12820): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
11-26 11:26:02.736: E/Database(12820): at android.os.Handler.dispatchMessage(Handler.java:99) 
11-26 11:26:02.736: E/Database(12820): at android.os.Looper.loop(Looper.java:123) 
11-26 11:26:02.736: E/Database(12820): at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-26 11:26:02.736: E/Database(12820): at java.lang.reflect.Method.invokeNative(Native Method) 
11-26 11:26:02.736: E/Database(12820): at java.lang.reflect.Method.invoke(Method.java:521) 
11-26 11:26:02.736: E/Database(12820): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-26 11:26:02.736: E/Database(12820): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
11-26 11:26:02.736: E/Database(12820): at dalvik.system.NativeStart.main(Native Method) 
+0

用'settings'表指針繼續後,終於閉上你的光標 – SathishKumar

+0

更新方法有無關光標! –

+0

http://stackoverflow.com/questions/13249129/close-the-cursor-and-db-when-use-the-sqlite-database檢查此更新 – SathishKumar

回答

0

DbHelper db = new DbHelper(context); 你必須關閉它。

public int update(String name, String value) { 
    DbHelper db = new DbHelper(context); 
    try { 
     db.openDataBase(); 
     ContentValues cv = new ContentValues(); 

     cv.put("value", value); 
     db.update("settings", cv, "name='" + name + "'"); 
    } catch (Exception e) { 
     xLog.error(e.getMessage()); 
    } finally { 
     db.closeDataBase(); 
    } 
    return 0; 
} 
在AndroidManifest

DbHelper級互聯網許可文件

private void openDataBase() throws SQLException { 
     database = databaseHelper.getWritableDatabase(); 
    } 

    private void closeDataBase() { 
     if (databaseHelper != null) { 
      databaseHelper.close(); 
     } 
    } 
+0

我發現問題在於調用Web服務。問題已更新。 –

相關問題