2011-11-01 41 views
0

我遇到與我的手機模型SQL Lite有問題的是LG Optimus One P500。我的手機android版本從FroYo更新到薑餅,更新對我來說很好。我的應用程序也適用於其他手機型號。添加SQL Lite代碼後關閉Android應用程序

應用程序起初也顯示我的主頁,但是當我開始遊戲時,問題出現,然後強制關閉我的應用程序。

數據庫創建(初始化)活動在評分頁面顯示後開始,所以我認爲問題不應該存在於我開始遊戲之後,但是所有這些問題都是在我添加數據庫代碼之後纔開始的。

爲了更好地理解我的行爲是這樣的:

  1. 在啓動時獲取名稱,然後在按下啓動按鈕變量 後一個字符串存儲的名稱。 (我的問題然後存在於這部分)
  2. 我有一個計時器和分數文本在我的第二個佈局,這將在遊戲結束後提取。
  3. 現在將創建數據庫(如果尚未存在),然後這3個數據將存儲在數據庫中。

這裏是我的數據庫代碼(我只是從一個教程得到它從網上):

public class DataHelper { 

    private static final String DATABASE_NAME = "scores.db"; 
     private static final int DATABASE_VERSION = 1; 
     private static final String TABLE_NAME = "tblScores"; 

     private Context context; 
     private SQLiteDatabase db; 

     private SQLiteStatement insertStmt; 
     private static final String INSERT = "insert into " 
      + TABLE_NAME + "(name,score,time) values (?,?,?)"; 

     public DataHelper(Context context) { 
       this.context = context; 
       OpenHelper openHelper = new OpenHelper(this.context); 
       this.db = openHelper.getWritableDatabase(); 
       this.insertStmt = this.db.compileStatement(INSERT); 
      } 

     public long insert(String name, String score, String time) { 
      this.insertStmt.bindString(1, name); 
      this.insertStmt.bindString(2, score); 
      this.insertStmt.bindString(3, time); 
      return this.insertStmt.executeInsert(); 
     } 

     public void deleteAll() { 
      this.db.delete(TABLE_NAME, null, null); 
     } 

     public List<String> selectAll() { 
       List<String> list = new ArrayList<String>(); 
       Cursor cursor = this.db.query(TABLE_NAME, new String[] { "name","score","time" }, 
       /*"name in ('A','B')"*/ null, null, /*"name"*/null, null, "score, time desc"); 
       if (cursor.moveToFirst()) { 
       do { 
        list.add(cursor.getString(0)+" "+cursor.getString(1)+" "+cursor.getString(2)); 
        //list.add(cursor.getString(1)); 
       } while (cursor.moveToNext()); 
       } 
       if (cursor != null && !cursor.isClosed()) { 
       cursor.close(); 
       } 
       return list; 
      } 

     private static class OpenHelper extends SQLiteOpenHelper { 

      OpenHelper(Context context) { 
      super(context, DATABASE_NAME, null, DATABASE_VERSION); 
      } 

      @Override 
      public void onCreate(SQLiteDatabase db) { 
      db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT, score TEXT, time TEXT)"); 
      } 

      @Override 
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
      Log.w("Example", "Upgrading database, this will drop tables and recreate."); 
      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
      onCreate(db); 
      } 
     } 
    } 

下面是從我的手機日誌文件:

[android.intent.category.LAUNCHER] flg=0x10200000 cmp=arc.android.memorygame/.Ma 
inActivity } from pid 1875 
D/PhoneWindow(1875): <!>com.android.internal.policy.impl.PhoneWindow 1472<!> co 
uldn't save which view has focus because the focused view com.jiubang.ggheart.ap 
[email protected] has no id. 
I/ActivityManager(1573): Start proc arc.android.memorygame for activity arc.and 
roid.memorygame/.MainActivity: pid=12927 uid=10098 gids={1015} 
I/ggheart (1875): <!>fs 742<!> onStop 
I/wpa_supplicant(1731): wpa_supplicant_get_scan_results: Start 
I/wpa_supplicant(1731): CTRL-EVENT-SCAN-RESULTS Ready 
I/wpa_supplicant(1731): wpa_supplicant_event_scan_results: ap_scan 1, disconne 
cted 0 
I/wpa_supplicant(1731): No suitable AP found. 
I/wpa_supplicant(1731): Setting scan request: 20 sec 0 usec 
I/dun_service(1481): process rmnet event 
I/dun_service(1481): rstate == DUN_RMNETSTATE_ERROR in dun_monitor_kevents 
V/WifiMonitor(1573): <!>android.net.wifi.WifiMonitor$MonitorThread 176<!> Event 
[Setting scan request: 20 sec 0 usec] 
I/#LGIME (1671): <!>com.jungle.android.utils.Glog 32<!> #### onStartInput: res 
tarting=false, fieldId=2131099699 
I/ActivityManager(1573): <!>com.android.server.am.ActivityRecord 444<!> Display 
ed arc.android.memorygame/.MainActivity: +1s490ms 
D/StatusBarPolicy(1657): [BRIGHTHY] 0. mDataNetType: 1 
D/StatusBarPolicy(1657): [BRIGHTHY] curNetwork=51502 curHPLMN=51502 
E/dalvikvm-heap(12927): 9850880-byte external allocation too large for this proc 
ess. 
E/GraphicsJNI(12927): VM won't let us allocate 9850880 bytes 
D/skia (12927): --- decoder->decode returned false 
W/dalvikvm(12927): threadid=1: thread exiting with uncaught exception (group=0x4 
0018560) 
E/AndroidRuntime(12927): FATAL EXCEPTION: main 
E/AndroidRuntime(12927): android.view.InflateException: Binary XML file line #2: 
Error inflating class <unknown> 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.createView(Layout 
Inflater.java:518) 
E/AndroidRuntime(12927):  at com.android.internal.policy.impl.PhoneLayoutI 
nflater.onCreateView(PhoneLayoutInflater.java:56) 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.createViewFromTag 
(LayoutInflater.java:568) 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.inflate(LayoutInf 
later.java:386) 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.inflate(LayoutInf 
later.java:320) 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.inflate(LayoutInf 
later.java:276) 
E/AndroidRuntime(12927):  at com.android.internal.policy.impl.PhoneWindow. 
setContentView(PhoneWindow.java:207) 
E/AndroidRuntime(12927):  at android.app.Activity.setContentView(Activity. 
java:1657) 
E/AndroidRuntime(12927):  at arc.android.memorygame.MainActivity.startGame 
(MainActivity.java:194) 
E/AndroidRuntime(12927):  at arc.android.memorygame.MainActivity$1.onClick 
(MainActivity.java:108) 
E/AndroidRuntime(12927):  at android.view.View.performClick(View.java:2485 
) 
E/AndroidRuntime(12927):  at android.view.View$PerformClick.run(View.java: 
9080) 
E/AndroidRuntime(12927):  at android.os.Handler.handleCallback(Handler.jav 
a:587) 
E/AndroidRuntime(12927):  at android.os.Handler.dispatchMessage(Handler.ja 
va:92) 
E/AndroidRuntime(12927):  at android.os.Looper.loop(Looper.java:123) 
E/AndroidRuntime(12927):  at android.app.ActivityThread.main(ActivityThrea 
d.java:3729) 
E/AndroidRuntime(12927):  at java.lang.reflect.Method.invokeNative(Native 
Method) 
E/AndroidRuntime(12927):  at java.lang.reflect.Method.invoke(Method.java:5 
07) 
E/AndroidRuntime(12927):  at com.android.internal.os.ZygoteInit$MethodAndA 
rgsCaller.run(ZygoteInit.java:874) 
E/AndroidRuntime(12927):  at com.android.internal.os.ZygoteInit.main(Zygot 
eInit.java:632) 
E/AndroidRuntime(12927):  at dalvik.system.NativeStart.main(Native Method) 

E/AndroidRuntime(12927): Caused by: java.lang.reflect.InvocationTargetException 
E/AndroidRuntime(12927):  at java.lang.reflect.Constructor.constructNative 
(Native Method) 
E/AndroidRuntime(12927):  at java.lang.reflect.Constructor.newInstance(Con 
structor.java:415) 
E/AndroidRuntime(12927):  at android.view.LayoutInflater.createView(Layout 
Inflater.java:505) 
E/AndroidRuntime(12927):  ... 20 more 
E/AndroidRuntime(12927): Caused by: java.lang.OutOfMemoryError: bitmap size exce 
eds VM budget 
E/AndroidRuntime(12927):  at android.graphics.BitmapFactory.nativeDecodeAs 
set(Native Method) 
E/AndroidRuntime(12927):  at android.graphics.BitmapFactory.decodeStream(B 
itmapFactory.java:460) 
E/AndroidRuntime(12927):  at android.graphics.BitmapFactory.decodeResource 
Stream(BitmapFactory.java:336) 
E/AndroidRuntime(12927):  at android.graphics.drawable.Drawable.createFrom 
ResourceStream(Drawable.java:697) 
E/AndroidRuntime(12927):  at android.content.res.Resources.loadDrawable(Re 
sources.java:1709) 
E/AndroidRuntime(12927):  at android.content.res.TypedArray.getDrawable(Ty 
pedArray.java:601) 
E/AndroidRuntime(12927):  at android.view.View.<init>(View.java:1951) 
E/AndroidRuntime(12927):  at android.view.View.<init>(View.java:1899) 
E/AndroidRuntime(12927):  at android.view.ViewGroup.<init>(ViewGroup.java: 
286) 
E/AndroidRuntime(12927):  at android.widget.LinearLayout.<init>(LinearLayo 
ut.java:120) 
E/AndroidRuntime(12927):  ... 23 more 
W/ActivityManager(1573): Force finishing activity arc.android.memorygame/.Mai 
nActivity 
W/ActivityManager(1573): Activity pause timeout for HistoryRecord{4070d4e8 arc. 
android.memorygame/.MainActivity} 
I/DemoService(1875): <!>fs 730<!> DiyScheduer.onStart 
I/ggheart (1875): <!>fs 732<!> onStart 
I/ActivityManager(1573): No longer want com.viber.voip:keepAliveReceiver (pid 2 
474): hidden #16 
D/StatusBarPolicy(1657): [BRIGHTHY] 0. mDataNetType: 1 
D/StatusBarPolicy(1657): [BRIGHTHY] curNetwork=51502 curHPLMN=51502 
I/#LGIME (1671): <!>com.jungle.android.utils.Glog 32<!> #### onStartInput: res 
tarting=false, fieldId=-1 
I/ActivityManager(1573): Process arc.android.memorygame (pid 12927) has died. 

而且,任何人都可以幫助我在Java中查詢?我是這個新手。正如你看到的,我只是編輯然後測試查詢命令。有關如何工作的詳細視圖將很好。

+4

你可以發佈崩潰的堆棧跟蹤,所以我們知道是什麼造成了它? –

+0

我不能,因爲你看到問題只發生在我的手機上,而在其他手機上工作正常。當我將它部署在我的模擬器上時,它也可以正常工作。我使用Android 2.2版本模擬器工作,並將其部署在2.2和2.3版本的手機上,除了我的手機是2.3更新版本之外,所有手機都可以正常工作。 – KaHeL

+0

您仍然可以查看logcat。只需使用'adb -d logcat'查看設備中的日誌。確保您的設備已連接到電腦並打開手機中的USB調試。 –

回答

0

好吧。例外是在那裏 - OutOfMemoryError同時膨脹一個位圖

+0

是的,它似乎是它的主要原因,但我想知道爲什麼它只發生在我的第一個版本工作正常,而我添加數據庫活動後? – KaHeL

+0

可能是因爲它以前是魔力,數據庫的額外開銷將其放在邊緣。 –

+0

我明白了,那麼這個解決方案呢? – KaHeL

相關問題