08-09 09:42:55.574: I/System.out(2370): cv------>SongType=guonei SongUrl=asd _id=11 SongName=zhangsan
08-09 09:42:55.585: D/AndroidRuntime(2370): Shutting down VM
08-09 09:42:55.595: W/dalvikvm(2370): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-09 09:42:55.595: E/AndroidRuntime(2370): Uncaught handler: thread main exiting due to uncaught exception
08-09 09:42:55.614: E/AndroidRuntime(2370): java.lang.NullPointerException
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.xiuman.XMPlayer_DB.DatabaseHelper.insertSong(DatabaseHelper.java:81)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.xiuman.XMPlayer_DB.MainActivity$InsertListener.onClick(MainActivity.java:54)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.View.performClick(View.java:2364)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.View.onTouchEvent(View.java:4179)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.widget.TextView.onTouchEvent(TextView.java:6541)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.View.dispatchTouchEvent(View.java:3709)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.os.Looper.loop(Looper.java:123)
08-09 09:42:55.614: E/AndroidRuntime(2370): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-09 09:42:55.614: E/AndroidRuntime(2370): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 09:42:55.614: E/AndroidRuntime(2370): at java.lang.reflect.Method.invoke(Method.java:521)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-09 09:42:55.614: E/AndroidRuntime(2370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-09 09:42:55.614: E/AndroidRuntime(2370): at dalvik.system.NativeStart.main(Native Method)
08-09 09:42:55.635: I/dalvikvm(2370): threadid=7: reacting to signal 3
08-09 09:42:55.635: E/dalvikvm(2370): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
package com.xiuman.XMPlayer_DB;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper{
private static final String DB_NAME = "XWPlayer_DB"; //数据库名
private static final int VERSION = 1;//数据库版本
private static final String TB_SONG = "Song_TB";
private static final String TB_PLAYERLIST = "PlayerList_TB";
public static final String Song_id = "_id";
public static final String Song_Name = "SongName";
public static final String Song_Url = "SongUrl";
public static final String Song_Type = "SongType";
public static final String PlayerList_id = "_id";
public static final String PlayerList_Name = "SongName";
public static final String PlayerList_SingerName = "SingerName";
private static SQLiteDatabase db;
private static DatabaseHelper DBHelper;
private final String Create_TB_SQL ="create Table "+TB_SONG+" (_id integer primary key autoincrement, SongName text not null, SongUrl text, SongType text)";
private final String Create_TB_SQL2 ="create table "+TB_PLAYERLIST+" (_id integer primary key autoincrement, SongName text not null, SingerName text not null)";
public DatabaseHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public DatabaseHelper(Context context, String name) {
this(context, DB_NAME, VERSION);
}
public DatabaseHelper(Context context, String name, int version) {
this(context, DB_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
System.out.println("execute create table sql");
db.execSQL(Create_TB_SQL);
db.execSQL(Create_TB_SQL2);
}
public DatabaseHelper open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL(Create_TB_SQL);
db.execSQL(Create_TB_SQL2);
onCreate(db);
}
/**
* 增加记录
*/
public long insertSong(int _id, String SongName, String SongUrl, String SongType) {
ContentValues cv = new ContentValues();
cv.put(Song_id, _id);
cv.put(Song_Name, SongName);
cv.put(Song_Url, SongUrl);
cv.put(Song_Type, SongType);
System.out.println("cv------>" + cv);
return db.insert(TB_SONG, null, cv);
}
public long insertPlayerList(String SongName, String SingerName) {
ContentValues cv = new ContentValues();
cv.put(PlayerList_Name, SongName);
cv.put(PlayerList_SingerName, SingerName);
return db.insert(TB_PLAYERLIST, null, cv);
}
/**
* 删除记录
*/
public int deleteSong(int _id) {
String[] whereValue={Integer.toString(_id)};
return db.delete(TB_SONG, "_id=?", whereValue);
}
public int deletePlayerList(int _id) {
String[] whereValue={Integer.toString(_id)};
return db.delete(TB_PLAYERLIST, "_id=?", whereValue);
}
/**
* 更新记录
*/
public int updateSong(int _id, String songName, String songUrl, String songType) {
ContentValues cv = new ContentValues();
String[] whereValue={Integer.toString(_id)};
cv.put(Song_Name, songName);
cv.put(Song_Url, songUrl);
cv.put(Song_Type, songType);
return db.update(TB_SONG, cv, "_id=?", whereValue);
}
public int updatePlayerList(int _id, String songname, String singername) {
ContentValues initialValues = new ContentValues();
String[] whereValue={Integer.toString(_id)};
initialValues.put(PlayerList_Name, songname);
initialValues.put(PlayerList_SingerName, singername);
return db.update(TB_PLAYERLIST, initialValues, "_id=?", whereValue);
}
/**
* 查询记录
*/
public Cursor selectSong() {
SQLiteDatabase db = getReadableDatabase();
return db.query(TB_SONG, new String[]{"_id","SongName","SongUrl", "SongType"}, "id=?", new String[]{"1"}, null, null, " _id desc");
}
public Cursor selectPlayerList() {
SQLiteDatabase db = getReadableDatabase();
return db.query(TB_PLAYERLIST, new String[]{"_id","SongName","SingerName"}, "id=?", new String[]{"1"}, null, null, " _id desc");
}
public List<Song> getAllSongObj()
{
List<Song> SongSet = new ArrayList<Song>();
Cursor c = db.query(TB_SONG, new String[] {Song_id, Song_Name, Song_Url, Song_Type},null,null,null,null,null);
for(c.moveToFirst(); ! c.isAfterLast(); c.moveToNext()){
Song song = new Song();
song.setSongId(c.getInt(0));
song.setSongName(c.getString(1));
song.setSongUrl(c.getString(2));
song.setSongType(c.getString(3));
SongSet.add(song);
}
c.close();
return SongSet;
}
public List<PlayerList> getAllPlayerListObj()
{
List<PlayerList> PlayerListSet = new ArrayList<PlayerList>();
Cursor c = db.query(TB_PLAYERLIST, new String[] {PlayerList_id, PlayerList_Name, PlayerList_SingerName},null,null,null,null,null);
for(c.moveToFirst(); ! c.isAfterLast(); c.moveToNext()){
PlayerList pl = new PlayerList();
pl.setId(c.getInt(0));
pl.setSongName(c.getString(1));
pl.setSingerName(c.getString(2));
PlayerListSet.add(pl);
}
c.close();
return PlayerListSet;
}
}
package com.xiuman.XMPlayer_DB;
import android.os.Bundle;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import com.xiuman.XMPlayer_DB.DatabaseHelper;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button createButton;
private Button insertButton;
private Button updateButton;
private Button updateRecordButton;
private Button queryButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
createButton = (Button)findViewById(R.id.createDatabase);
updateButton = (Button)findViewById(R.id.updateDatabase);
insertButton = (Button)findViewById(R.id.insert);
updateRecordButton = (Button)findViewById(R.id.update);
queryButton = (Button)findViewById(R.id.query);
createButton.setOnClickListener(new CreateListener());
updateButton.setOnClickListener(new UpdateListener());
insertButton.setOnClickListener(new InsertListener());
updateRecordButton.setOnClickListener(new UpdateRecordListener());
queryButton.setOnClickListener(new QueryListener());
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this, "XWPlayer_DB");
}
class CreateListener implements OnClickListener{
public void onClick(View v) {
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this,"XWPlayer_DB");
SQLiteDatabase db = dbHelper.getReadableDatabase();
}
}
class UpdateListener implements OnClickListener{
public void onClick(View v) {
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this,"XWPlayer_DB",2);
SQLiteDatabase db = dbHelper.getReadableDatabase();
}
}
class InsertListener implements OnClickListener{
public void onClick(View v) {
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this,"XWPlayer_DB", 2);
dbHelper.insertSong(1, "zhangsan", "asd", "guonei");
}
}
class UpdateRecordListener implements OnClickListener{
public void onClick(View arg0) {
// TODO Auto-generated method stub
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this,"XWPlayer_DB");
SQLiteDatabase db = dbHelper.getWritableDatabase();
dbHelper.updateSong(12, "zhangsanfeng", "asd", "国内");
}
}
class QueryListener implements OnClickListener{
public void onClick(View v) {
System.out.println("aaa------------------");
Log.d("myDebug", "myFirstDebugMsg");
DatabaseHelper dbHelper = new DatabaseHelper(MainActivity.this,"XWPlayer_DB");
dbHelper.selectSong();
}
}
}
ContentValues cv = new ContentValues();
cv.put(Song_Name, SongName);
cv.put(Song_Url, SongUrl);
cv.put(Song_Type, SongType);
System.out.println("cv------>" + cv);
open();
return db.insert(TB_SONG, "SongName, SongUrl, SongType", cv);
08-09 15:35:51.208: E/AndroidRuntime(525): Uncaught handler: thread main exiting due to uncaught exception
08-09 15:35:51.248: E/AndroidRuntime(525): java.lang.NullPointerException
08-09 15:35:51.248: E/AndroidRuntime(525): at com.xiuman.XMPlayer_DB.DatabaseHelper.open(DatabaseHelper.java:59)
08-09 15:35:51.248: E/AndroidRuntime(525): at com.xiuman.XMPlayer_DB.DatabaseHelper.insertSong(DatabaseHelper.java:79)
08-09 15:35:51.248: E/AndroidRuntime(525): at com.xiuman.XMPlayer_DB.MainActivity$InsertListener.onClick(MainActivity.java:54)
08-09 16:45:29.185: E/AndroidRuntime(647): Uncaught handler: thread main exiting due to uncaught exception
08-09 16:45:29.225: E/AndroidRuntime(647): android.database.sqlite.SQLiteException: no such column: id: , while compiling: SELECT _id, SongName, SongUrl, SongType FROM Song_TB WHERE id=? ORDER BY _id desc
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1221)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1108)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1066)
08-09 16:45:29.225: E/AndroidRuntime(647): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1143)
08-09 16:45:29.225: E/AndroidRuntime(647): at com.xiuman.XMPlayer_DB.DatabaseHelper.selectSong(DatabaseHelper.java:134)
08-09 16:45:29.225: E/AndroidRuntime(647): at com.xiuman.XMPlayer_DB.MainActivity$QueryListener.onClick(MainActivity.java:74)
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。