解决方案 »
- 用android sdk4.0 开发的软件可以在2.3的系统上运行吗?
- 如何通过wifi管理Android手机Sdcard(开发)
- WAP网站(PHP版)怎么获取客户端的手机号(移动、联通、电信),
- android socket 通信中有阻塞式的读取吗;尝试了bufferreader.readline似乎不会阻塞;
- webview载入页面和手机的网有关吗?在线等
- Activity的onCreate中无法调用AnimationDrawable的Draw方法
- xml添加了发送短信权限,还是不能发送短信
- 帅哥美女们速度进来看看啊
- Android的MediaRecoder视频分割问题
- listview点击选中
- 关于键盘遮盖的问题,有图,公司大哥大姐改不出来,让小弟改,大伙看看,感激不尽。
- 为什么Android控件有时候要点两下才有效果
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); 这个地方要改成:ContentValues cv = new ContentValues();
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, "SongName, SongUrl, SongType", cv);
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_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); 这个地方要改成: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);
59行:db = DBHelper.getWritableDatabase(); 出错!
log: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)
this(context, DB_NAME, VERSION);
}
public DatabaseHelper(Context context, String name, int version)
{
this(context, DB_NAME, null, VERSION);
}
改为: public DatabaseHelper(Context context, String name) {
this(context, DB_NAME, VERSION);
DBHelper = new DatabaseHelper(context, DB_NAME, null, VERSION);
}
public DatabaseHelper(Context context, String name, int version)
{
this(context, DB_NAME, null, VERSION);
DBHelper = new DatabaseHelper(context, DB_NAME, null, VERSION);
}看看
插入和更新都可以;饿 现在就查询还是报错
134行: return db.query(TB_SONG, new String[]{"_id","SongName","SongUrl", "SongType"}, "id=?", new String[]{"1"}, null, null, " _id desc");
log: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)