2013-08-28 32 views
-3

我想解析包含」到SQL中的XML字符串,但我得到一個錯誤,它崩潰了我的應用程序。
我試着用"更換「,但它是在我的應用程序創建一個錯誤
反正是有解決這個問題解析「字符串從XML到SQL在Android中

<drug> 
    <id>5</id> 
    <genericName>SIMVASTATIN</genericName> 
    <brandName>Zocor</brandName> 
    <therapueticClass>HMG-CoA Reductase Inhibitor/"statin"</therapueticClass> 
    <commonPurpose>reduce total-Cholesterol, LDL, TG and Increase HDL</commonPurpose> 
    <dosing>10-40mg daily</dosing> 
    <commonAE>Abdominal Pain</commonAE> 
    <blackBoxWarning>Liver Disease</blackBoxWarning> 
    <beersList>No</beersList> 
    <keyPoint>N/A</keyPoint> 
    <picture>drug.jpg</picture> 
    <drug> 

Logcat: 
08-28 16:46:11.733: D/dalvikvm(859): GC_FOR_ALLOC freed 46K, 7% free 2563K/2732K, paused 28ms, total 30ms 
08-28 16:46:11.733: I/dalvikvm-heap(859): Grow heap (frag case) to 3.224MB for 635812-byte allocation 
08-28 16:46:11.783: D/dalvikvm(859): GC_FOR_ALLOC freed 2K, 6% free 3181K/3356K, paused 48ms, total 48ms 
08-28 16:46:11.843: D/dalvikvm(859): GC_CONCURRENT freed 1K, 5% free 3197K/3356K, paused 12ms+4ms, total 61ms 
08-28 16:46:11.993: D/gralloc_goldfish(859): Emulator without GPU emulation detected. 
08-28 16:46:13.843: E/SQLiteLog(859): (1) near "statin": syntax error 
08-28 16:46:13.883: W/dalvikvm(859): threadid=11: thread exiting with uncaught exception (group=0x40a71930) 
08-28 16:46:14.033: E/AndroidRuntime(859): FATAL EXCEPTION: AsyncTask #1 
08-28 16:46:14.033: E/AndroidRuntime(859): java.lang.RuntimeException: An error occured while executing doInBackground() 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$3.done(AsyncTask.java:299) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.lang.Thread.run(Thread.java:856) 
08-28 16:46:14.033: E/AndroidRuntime(859): Caused by: android.database.sqlite.SQLiteException: near "statin": syntax error (code 1): , while compiling: INSERT INTO drugs (generic_name, brand_name, therapueticClass, commonPurpose, dosing, commonAE, blackBoxWarning, beersList, keyPoint, picture) values ("SIMVASTATIN", "Zocor", "HMG-CoA Reductase Inhibitor/"statin"", "reduce total-Cholesterol, LDL, TG and Increase HDL", "10-40mg daily", "Abdominal Pain", "Liver Disease", "No", "N/A", "drug.jpg"); 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) 
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugDatabase.seedData(DrugDatabase.java:69) 
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugDatabase.onCreate(DrugDatabase.java:52) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.DrugProvider.query(DrugProvider.java:87) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentProvider.query(ContentProvider.java:652) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentProvider$Transport.query(ContentProvider.java:189) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentResolver.query(ContentResolver.java:372) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.content.ContentResolver.query(ContentResolver.java:315) 
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.MainActivity$LoadDrugsTask.doInBackground(MainActivity.java:78) 
08-28 16:46:14.033: E/AndroidRuntime(859): at edu.pacific.pocketrx.MainActivity$LoadDrugsTask.doInBackground(MainActivity.java:1) 
08-28 16:46:14.033: E/AndroidRuntime(859): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
08-28 16:46:14.033: E/AndroidRuntime(859): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
08-28 16:46:14.033: E/AndroidRuntime(859): ... 4 more 

編輯:我是否能夠通過使用報價將此行代碼更改爲:

<therapueticClass>HMG-CoA Reductase Inhibitor/""statin""</therapueticClass> 
+1

請張貼代碼和你的logcat也得到更好地瞭解您的問題。 – GrIsHu

+1

發佈您的logcat錯誤,併發布一些代碼... – Hariharan

回答

1

嘗試......

"HMG-CoA Reductase Inhibitor \"statin\"" 
1

您看到的問題是因爲therapueticClass標記contai ns報價。

<therapueticClass>HMG-CoA Reductase Inhibitor/"statin"</therapueticClass> 

刪除它在插入它的地方。

+0

反正有沒有其他方式使用報價? –

+0

我能夠做到這一點,我用雙引號。我將它改爲 HMG-CoA還原酶抑制劑/「」他汀類藥物「」