我想要做的是将我的微调器中选择的信息放入sqlite数据库,并且看起来很好但是当我调试我的应用程序并启动此活动时它停止工作,这是我的代码:
public class Materiales extends Activity implements OnClickListener, OnItemSelectedListener {
/* (non-Javadoc)
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.materiales);
Spinner sp1, sp2, sp3;
Button spb;
sp1 = (Spinner) findViewById(R.id.sp1);
sp2 = (Spinner) findViewById(R.id.sp2);
sp3 = (Spinner) findViewById(R.id.sp3);
spb = (Button) findViewById(R.id.matb);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.tirocarga_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp1.setAdapter(adapter);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
this, R.array.materiales_array, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp2.setAdapter(adapter1);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
this, R.array.place_array, android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp3.setAdapter(adapter2);
spb.setOnClickListener(this);
sp1.setOnItemSelectedListener(this);
sp2.setOnItemSelectedListener(this);
sp3.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
String selectedItem = parent.getItemAtPosition(pos).toString();
Spinner spinner = (Spinner) parent;
if(spinner.getId() == R.id.sp1)
{
DataBase entry = new DataBase(Materiales.this);
entry.open();
entry.createEntry1(selectedItem);
entry.close();
}
else if(spinner.getId() == R.id.sp2)
{
DataBase entry = new DataBase(Materiales.this);
entry.open();
entry.createEntry2(selectedItem);
entry.close();
}
else if(spinner.getId() == R.id.sp3)
{
DataBase entry = new DataBase(Materiales.this);
entry.open();
entry.createEntry3(selectedItem);
entry.close();
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.matb:
startActivity(new Intent(this, Senprint.class));
break;
}
}
感谢您的帮助 这是错误的日志 02-06 12:28:16.719:E / Trace(3861):错误打开跟踪文件:没有这样的文件或目录(2) 02-06 12:28:20.243:E / SQLiteLog(3861):( 1)靠近“TABLEcontent”:语法错误 02-06 12:28:20.373:E / SQLiteLog(3861):( 1)靠近“TABLEcontent”:语法错误 02-06 12:28:20.383:E / AndroidRuntime(3861):致命异常:主要 02-06 12:28:20.383:E / AndroidRuntime(3861):android.database.sqlite.SQLiteException:near“TABLEcontent”:语法错误(代码1):,编译时:CREATE TABLEcontent(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,fechaSTAMP NOT NULL DEFAULT current_timestamp,infoTEXT NOT NULL; materialesTEXT NOT NULL); 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594) 02-06 12:28:20.383:E / AndroidRuntime(3861):at com.ipssum.coconal.DataBase $ Dbhelper.onCreate(DataBase.java:39) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 02-06 12:28:20.383:E / AndroidRuntime(3861):at com.ipssum.coconal.DataBase.open(DataBase.java:61) 02-06 12:28:20.383:E / AndroidRuntime(3861):at com.ipssum.coconal.Materiales.onItemSelected(Materiales.java:61) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.widget.AdapterView.fireOnSelected(AdapterView.java:892) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.widget.AdapterView.access $ 200(AdapterView.java:49) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.widget.AdapterView $ SelectionNotifier.run(AdapterView.java:860) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.os.Handler.handleCallback(Handler.java:615) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.os.Handler.dispatchMessage(Handler.java:92) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.os.Looper.loop(Looper.java:137) 02-06 12:28:20.383:E / AndroidRuntime(3861):在android.app.ActivityThread.main(ActivityThread.java:4800) 02-06 12:28:20.383:E / AndroidRuntime(3861):at java.lang.reflect.Method.invokeNative(Native Method) 02-06 12:28:20.383:E / AndroidRuntime(3861):at java.lang.reflect.Method.invoke(Method.java:511) 02-06 12:28:20.383:E / AndroidRuntime(3861):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:798) 02-06 12:28:20.383:E / AndroidRuntime(3861):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 02-06 12:28:20.383:E / AndroidRuntime(3861):at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
从跟踪看起来你的create table语句本身有问题...请用适当的间距清理create table语句。
答案 1 :(得分:0)
CREATE TABLE content(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, fecha TIMESTAMP NOT NULL DEFAULT current_timestamp, info TEXT NOT NULL, materiales TEXT NOT NULL);
请注意TABLE和内容之间以及sql
中其他关键字之间的间距