解决方案 »
- android模拟器一直停在这个启动界面是怎么回事啊。。
- 始终无法接收到广播 请高手帮忙
- 为什么数据库表的字段经过更新后的值仍然没有改变?代码见内容
- 关于post传输,接收返回值的问题.
- 小弟今年刚大四,以后想做android或ios,或者游戏开发。不知道选哪个更好,大神们给点建议吧
- 请问哪里有开源的比较成熟的APP产品的源码?
- 谁有TTS现成的实现工具?
- 关于抽屉导航和tab标签导航
- android通过NDK调用一个C++算法,算法使用到opencv,opencv库该怎么弄进去??
- 模拟器或者真机如何拿到权限查看data下的文件
- android手机无法调用pc机上的webservice
- buildDrawingCache 如何设置成RGB_565?
05-10 14:24:47.528: ERROR/Zygote(32): setreuid() failed. errno: 17
05-10 14:24:48.968: ERROR/BatteryService(58): usbOnlinePath not found
05-10 14:24:48.968: ERROR/BatteryService(58): batteryVoltagePath not found
05-10 14:24:48.968: ERROR/BatteryService(58): batteryTemperaturePath not found
05-10 14:24:48.998: ERROR/SurfaceFlinger(58): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
05-10 14:24:55.769: ERROR/EventHub(58): could not get driver version for /dev/input/mouse0, Not a typewriter
05-10 14:24:55.769: ERROR/EventHub(58): could not get driver version for /dev/input/mice, Not a typewriter
05-10 14:24:56.009: ERROR/System(58): Failure starting core service
05-10 14:24:56.009: ERROR/System(58): java.lang.SecurityException
05-10 14:24:56.009: ERROR/System(58): at android.os.BinderProxy.transact(Native Method)
05-10 14:24:56.009: ERROR/System(58): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
05-10 14:24:56.009: ERROR/System(58): at android.os.ServiceManager.addService(ServiceManager.java:72)
05-10 14:24:56.009: ERROR/System(58): at com.android.server.ServerThread.run(SystemServer.java:184)
05-10 14:24:57.149: ERROR/SoundPool(58): error loading /system/media/audio/ui/Effect_Tick.ogg
05-10 14:24:57.149: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressStandard.ogg
05-10 14:24:57.169: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-10 14:24:57.169: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressDelete.ogg
05-10 14:24:57.169: ERROR/SoundPool(58): error loading /system/media/audio/ui/KeypressReturn.ogg
05-10 14:24:59.689: ERROR/ThrottleService(58): Could not open GPS configuration file /etc/gps.conf
05-10 14:25:01.529: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
05-10 14:25:01.569: ERROR/logwrapper(148): executing /system/bin/tc failed: No such file or directory
05-10 14:25:01.639: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
05-10 14:25:14.804: ERROR/HierarchicalStateMachine(58): TetherMaster - unhandledMessage: msg.what=3
05-10 14:25:38.444: ERROR/Database(277): Failure 1 (near "TABLEUsers": syntax error) on 0x1e6850 when preparing 'CREATE TABLEUsers(_idINTEGER primary key autoincrement,user_nametext not null,telephonetext not null,addresstext not null,mail_addresstext not null,);'.
05-10 14:25:38.524: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
05-10 14:25:38.524: ERROR/AndroidRuntime(277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.SQLiteTest3}: android.database.sqlite.SQLiteException: near "TABLEUsers": syntax error: CREATE TABLEUsers(_idINTEGER primary key autoincrement,user_nametext not null,telephonetext not null,addresstext not null,mail_addresstext not null,);
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): Caused by: android.database.sqlite.SQLiteException: near "TABLEUsers": syntax error: CREATE TABLEUsers(_idINTEGER primary key autoincrement,user_nametext not null,telephonetext not null,addresstext not null,mail_addresstext not null,);
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at com.test.SQLiteTest3$DBConnection.onCreate(SQLiteTest3.java:182)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at com.test.SQLiteTest3.onCreate(SQLiteTest3.java:52)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 14:25:38.524: ERROR/AndroidRuntime(277): ... 11 more第一次发帖 还不怎么会 呵呵...
+ UserSchema.ID + " INTEGER primary key autoincrement, "
+ UserSchema.USER_NAME + " text not null,"
+ UserSchema.TELEPHONE + " text not null,"
+ UserSchema.ADDRESS + " text not null,"
+ UserSchema.MAIL_ADDRESS + " text not null," + ");";
db.execSQL(sql);
这就是楼主程序出错的原因:CTEATE TABLEusers出错,即sql语句出错啦
String sql = "CREATE TABLE " + UserSchema.TABLE_NAME + "("
+ UserSchema.ID + " INTEGER primary key autoincrement, "
+ UserSchema.USER_NAME + " text not null,"
+ UserSchema.TELEPHONE + " text not null,"
+ UserSchema.ADDRESS + " text not null,"
+ UserSchema.MAIL_ADDRESS + " text not null," + ");";db.execSQL(sql);
楼主试试吧!
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;public class SQLiteTest3 extends Activity {
/** Called when the activity is first created. */
OnClickListener listener_add = null;
OnClickListener listener_update = null;
OnClickListener listener_delete = null;
OnClickListener listener_clear = null;
Button button_add = null;
Button button_update = null;
Button button_delete = null;
Button button_clear = null;
DBConnection helper;
public int id_this; public interface UserSchema {
String TABLE_NAME = "Users";
String ID = "_id";
String USER_NAME = "user_name";
String ADDRESS = "address";
String TELEPHONE = "telephone";
String MAIL_ADDRESS = "mail_address";
} @Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText editText01 = (EditText) findViewById(R.id.EditText01);
final EditText editText02 = (EditText) findViewById(R.id.EditText02);
final EditText editText03 = (EditText) findViewById(R.id.EditText03);
final EditText editText04 = (EditText) findViewById(R.id.EditText04);
helper = new DBConnection(this);
final SQLiteDatabase db = helper.getWritableDatabase();
final String [] FROM = { UserSchema.ID, UserSchema.USER_NAME,
UserSchema.TELEPHONE, UserSchema.ADDRESS,
UserSchema.MAIL_ADDRESS };
System.out.println(1); Cursor c = db.query(UserSchema.TABLE_NAME,
new String [] { UserSchema.USER_NAME }, null, null, null, null,
null);
c.moveToFirst();
CharSequence [] list = new CharSequence[c.getCount()];
for (int i = 0; i < list.length; i++) {
list[i] = c.getString(0);
c.moveToNext();
}
c.close();
System.out.println(2);
Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
spinner.setAdapter(new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_spinner_item, list));
spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String user_name = ((Spinner) parent).getSelectedItem()
.toString();
Cursor c = db.query("Users", FROM, "user_name ='" + user_name
+ "'", null, null, null, null);
c.moveToFirst();
System.out.println(3);
id_this = Integer.parseInt(c.getString(0));
String user_name_this = c.getString(1);
String telephone_this = c.getString(2);
String address_this = c.getString(3);
String mail_address_this = c.getString(4);
c.close();
editText01.setText(user_name_this);
editText02.setText(telephone_this);
editText03.setText(address_this);
editText04.setText(mail_address_this); } public void onNothingSelected(AdapterView<?> parent) { }
});
listener_add = new OnClickListener() { public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(UserSchema.USER_NAME, editText01.getText()
.toString());
values.put(UserSchema.TELEPHONE, editText02.getText()
.toString());
values.put(UserSchema.MAIL_ADDRESS, editText03.getText()
.toString());
values.put(UserSchema.ADDRESS, editText04.getText().toString());
SQLiteDatabase db = helper.getWritableDatabase();
System.out.println(4);
db.insert(UserSchema.TABLE_NAME, null, values);
System.out.println(5);
db.close();
onCreate(savedInstanceState);
}
};
listener_update = new OnClickListener() { public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(UserSchema.USER_NAME, editText01.getText()
.toString());
values.put(UserSchema.TELEPHONE, editText02.getText()
.toString());
values.put(UserSchema.MAIL_ADDRESS, editText03.getText()
.toString());
values.put(UserSchema.ADDRESS, editText04.getText().toString());
String where = UserSchema.ID + " = " + id_this;
SQLiteDatabase db = helper.getWritableDatabase();
db.update(UserSchema.TABLE_NAME, values, where, null);
db.close();
onCreate(savedInstanceState); }
};
listener_delete = new OnClickListener() { public void onClick(View v) {
String where = UserSchema.ID + "=" + id_this;
SQLiteDatabase db = helper.getWritableDatabase();
db.delete(UserSchema.TABLE_NAME, where, null);
db.close();
onCreate(savedInstanceState);
}
};
listener_clear = new OnClickListener() { public void onClick(View v) {
// TODO Auto-generated method stub
editText01.setText("");
editText02.setText("");
editText04.setText("");
editText03.setText(""); }
};
button_add = (Button) findViewById(R.id.Button01);
button_add.setOnClickListener(listener_add);
button_update = (Button) findViewById(R.id.Button02);
button_update.setOnClickListener(listener_update);
button_delete = (Button) findViewById(R.id.Button03);
button_delete.setOnClickListener(listener_delete);
button_clear = (Button) findViewById(R.id.Button04);
button_clear.setOnClickListener(listener_clear); } public static class DBConnection extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "PhoneBookDB";
private static final int DATABASE_VERTION = 1; private DBConnection(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERTION); }
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String sql = " CREATE TABLE " + UserSchema.TABLE_NAME + "("
+ UserSchema.ID + " INTEGER primary key autoincrement,"
+ UserSchema.USER_NAME + " text not null , "
+ UserSchema.TELEPHONE + " text not null , "
+ UserSchema.ADDRESS + " text not null , "
+ UserSchema.MAIL_ADDRESS + " text not null " + " ) ";
System.out.println(sql);
db.execSQL(sql); } @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub } }
}终于搞定了 就错在两个空格上了
看来还是粗心不得啊
不过还得谢谢帮助我的人
学习了!