为什么点击后总是Stop?

朱金仁 发布于 2013/09/03 20:43
阅读 251
收藏 0

刚学SQLite碰到问题,向大家请教,请不吝赐教!谢谢

public class SQLiteDatabaseDemoActivity extends Activity {
     private Button createDBbut;
    /* private Button updateDBbut;
     private Button insertbut;
     private Button updatebut;
     private Button querybut;*/
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  createDBbut=(Button) findViewById(R.id.createdb);
  /*updateDBbut=(Button) findViewById(R.id.updatedb);
  insertbut=(Button) findViewById(R.id.insert);
  updatebut=(Button) findViewById(R.id.update);
  querybut=(Button) findViewById(R.id.query);*/
  createDBbut.setOnClickListener(new createDBbutListener());
 
  }   
 class createDBbutListener implements OnClickListener{

  @Override
  public void onClick(View v) {
   // TODO Auto-generated method stub
   SQLiteDatabaseDemo helper=new SQLiteDatabaseDemo(SQLiteDatabaseDemoActivity.this, "test_mars_db");
   SQLiteDatabase db=helper.getReadableDatabase();
  }  
 }
}
  

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
/*SQLiteOpenHelper作为访问SQLite的助手类。提供两方面的功能
 * 1.getReadableDatabase(),getWritableDatabase()可以获得SQLiteDatabase对象
 * 2.提供了onCreate()和onUpgrade()两个回调函数
 * **/
public class SQLiteDatabaseDemo extends SQLiteOpenHelper {
 public static final int VERSION=1;
 public SQLiteDatabaseDemo(Context context, String name, CursorFactory factory,
   int version) {
  super(context,name, factory, version);//  通过super调用父类中的构造函数
  // TODO Auto-generated constructor stub
 }
 public SQLiteDatabaseDemo(Context context,String name){
  this(context,name,VERSION);
 }
 public SQLiteDatabaseDemo(Context context,String name,int version){
  this(context,name,null,version);
 }

 @Override
 public void onCreate(SQLiteDatabase db) {   //创建数据表
  // TODO Auto-generated method stub
        System.out.println("**********创建数据库OnCreate()********");
        db.execSQL("create table user(id int,name varchar(20) )");
 }

 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  // TODO Auto-generated method stub    
        System.out.println("**********更新数据库OnUpdate()********");     
 }
}

 

FATAL EXCEPTION: main

android.database.sqlite.SQLiteException: Can't downgrade database from version 2 to 1

at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:361)

 

加载中
返回顶部
顶部