package com.cxw.sqliteopenhelper;import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.Menu;public class OpenHelperMainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_helper_main);
MyDBHelper helper=new MyDBHelper(this);
helper.insert();
helper.query();
}
class MyDBHelper extends SQLiteOpenHelper{
private static final String CREATE_TABLE_SQL=" create table TempTb1(_id integer,name text) ";
private SQLiteDatabase db;
MyDBHelper(Context c)
{
super(c,"test.db",null,2);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(CREATE_TABLE_SQL);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
private void insert()
{
String sql="insert into TempTbl(_id,neme) values(1,'chenxiaowei')";
getWritableDatabase().execSQL(sql);
}
private void query()
{
Cursor c=getWritableDatabase().query("TempTb1", null, null, null, null, null, null);
if(c.moveToFirst())
{
for(int i=0;i<c.getCount();i++)
{
c.move(i);
int id=c.getInt(0);
String name=c.getString(1);
System.out.print(id+":"+name);
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_open_helper_main, menu);
return true;
}}
各位大哥帮小弟看一下这段代码怎么修改?提醒如下错误:
09-20 02:39:15.284: E/AndroidRuntime(1175): at com.cxw.sqliteopenhelper.OpenHelperMainActivity$MyDBHelper.access$0(OpenHelperMainActivity.java:39)
09-20 02:39:15.284: E/AndroidRuntime(1175): at com.cxw.sqliteopenhelper.OpenHelperMainActivity.onCreate(OpenHelperMainActivity.java:18)
androidSqlite
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.Menu;public class OpenHelperMainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_helper_main);
MyDBHelper helper=new MyDBHelper(this);
helper.insert();
helper.query();
}
class MyDBHelper extends SQLiteOpenHelper{
private static final String CREATE_TABLE_SQL=" create table TempTb1(_id integer,name text) ";
private SQLiteDatabase db;
MyDBHelper(Context c)
{
super(c,"test.db",null,2);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(CREATE_TABLE_SQL);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
private void insert()
{
String sql="insert into TempTbl(_id,neme) values(1,'chenxiaowei')";
getWritableDatabase().execSQL(sql);
}
private void query()
{
Cursor c=getWritableDatabase().query("TempTb1", null, null, null, null, null, null);
if(c.moveToFirst())
{
for(int i=0;i<c.getCount();i++)
{
c.move(i);
int id=c.getInt(0);
String name=c.getString(1);
System.out.print(id+":"+name);
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_open_helper_main, menu);
return true;
}}
各位大哥帮小弟看一下这段代码怎么修改?提醒如下错误:
09-20 02:39:15.284: E/AndroidRuntime(1175): at com.cxw.sqliteopenhelper.OpenHelperMainActivity$MyDBHelper.access$0(OpenHelperMainActivity.java:39)
09-20 02:39:15.284: E/AndroidRuntime(1175): at com.cxw.sqliteopenhelper.OpenHelperMainActivity.onCreate(OpenHelperMainActivity.java:18)
androidSqlite
解决方案 »
- 控件长按拖动那种功能怎样实现
- android平台创建数据库的问题。。。
- Android应用开发前景如何
- *** 请教,android怎么获得正在运行程序的程序名和图标??? ***
- Android 都支持哪些数据库
- android客户端如何获取Tomcat服务器的列表?急急急!!!
- 怎样将得到的数据添加到通知栏中
- FragmentActivity与ViewPage切换 getItem执行了两遍,是错误还是本来就这样
- 编写安卓端操作SD卡的程序,在虚拟机上可以用,在真实手机上却不行
- Android中错误的Activity onNewIntent被调用
- android popupwindow为什么不能移除屏幕
- 各位大大,求一个彻底退出自己开发的Android程序的方法?
{
String sql="insert into TempTbl(_id,neme) values(1,'chenxiaowei')";
getWritableDatabase().execSQL(sql);
}表名错了哟 改成TempTb1
( ・ิω・ิ)
09-20 06:21:55.330: E/AndroidRuntime(2302): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cxw.sqliteopenhelper/com.cxw.sqliteopenhelper.OpenHelperMainActivity}: android.database.CursorIndexOutOfBoundsException: Index 17 requested, with a size of 17
09-20 06:21:55.330: E/AndroidRuntime(2302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-20 06:21:55.330: E/AndroidRuntime(2302): at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:68)
09-20 06:21:55.330: E/AndroidRuntime(2302): at com.cxw.sqliteopenhelper.OpenHelperMainActivity$MyDBHelper.query(OpenHelperMainActivity.java:57)
那个早上我已经找出来了,现在是这个问题,怎解?跪求