应用程序卡住了

时间:2013-04-29 16:09:08

标签: android

我正在开发一个应用程序并编写了一个游标来从数据库中检索数据,但是在启动应用程序之后,它会在某个时候停滞不前。

logcat的:

04-29 16:05:23.328: I/System.out(9429): Database is opened
04-29 16:05:23.737: I/Choreographer(9429): Skipped 31 frames!  The application may be doing too much work on its main thread.
04-29 16:05:23.817: D/gralloc_goldfish(9429): Emulator without GPU emulation detected.

任何人都可以建议可以采取哪些措施来解决这个问题? 码: 当控件进入“数据库打开”时,我的代码就像这样,它不会继续前进。同时我试图从数据库中插入和检索数据。

import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

import com.example.project.R;

public class Database  extends SQLiteOpenHelper{

    static final String dbname="Project";
    static final int dbversion=1;

    TableA r=new TableA();


    SQLiteDatabase db;
    private Context Context;
    public Database(Context context) {
        super(context,  dbname, null, dbversion);
        try{
        db=getWritableDatabase();
        // TODO Auto-generated constructor stub
        if (db.isOpen()){

            System.out.println("Database is opened");
        }
            else{


                System.out.println("Database is not opened");
            }

        }
        catch(Exception e){

            Log.e(dbname, e.getMessage());

        }
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        // TODO Auto-generated method stub
        try{
        db.beginTransaction();

        db.execSQL(r.r_Table);


        db.insert(r.Tablename, null, r.insertdata());
        db.setTransactionSuccessful();
        retrivedata();
        }
        catch(Exception e){

            android.util.Log.e(r.Tablename, e.getMessage());

        }

        finally{

            db.endTransaction();
        }


    }//

    public void retrivedata(){

    Cursor c=db.rawQuery("Select * from Region", null);

    if (c != null ) {
        if  (c.moveToFirst()) {

            System.out.println("Rows are:"+c.getCount());

    }


}
    c.close();

}
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }

}

由于 希瓦

0 个答案:

没有答案