2014-01-23 24 views
0

什麼即時試圖做的是讓信息在我的紡紗選入SQLite數據庫,並everithing看起來不錯,但是當我調試我的應用程序,並開始這個活動就停止工作,這裏是我的代碼:如何存儲來自微調陣列適配器的數據庫信息?

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)near「TABLEcontent」:syntax error 02- 06 12:28:20.383:E/AndroidRuntime(3861):致命例外:main 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不爲NULL DEFAULT current_timestamp,infoTEXT NOT NULL; materialesTEXT NOT NULL);在Android中的E:/ AndroidRuntime(3861):at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 02-06 12:28:20.383:E/AndroidRuntime(3861):at android .database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 02-06 12:28:20.383:E/AndroidRuntime(3861):at 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):at android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31) 02-06 12:28:20.383:E/AndroidRuntime(3861) :at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663) 02-06 12:28:20.383:E/AndroidRuntime(3861):at 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):at 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):at android.widget.AdapterView.fireOnSelected(AdapterView.java:892) 02-06 12:28:20.383:E/AndroidRuntime(3861):at android.widget.AdapterView.access $ 200(AdapterView.java:49) 02-06 12:28:20.383:E/AndroidRuntime(3861):at android.widget.AdapterView $ SelectionNotifier.run(AdapterView.java:860) 02-06 12:28:20.383:E/AndroidRuntime(3861):at android.os.Handler.handleCallback(Handler.java:615) 02-06 12:28:20.383:E/AndroidRuntime(3861):at android .os.Handler.dispatchMessage(Handler.java:92) 02-06 12:28:20.383:E/AndroidRuntime(3861):at 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/A ndroidRuntime(3861):在java.lang.reflect.Method.invokeNative(本地方法) 02-06 12:28:20.383:E/AndroidRuntime(3861):在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):在dalvik.system.NativeStart.main(本機方法)

+0

之間界定「停止工作」。它會引發錯誤? – spezzino

+0

是致命錯誤,應用程序剛剛關閉 –

+0

您可以發佈logcat中顯示的堆棧跟蹤嗎? – spezzino

回答

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);  

請注意表和內容之間的間距,和其它關鍵字用SQL

+0

嗨,感謝您的幫助,我修復了我的數據庫,但問題仍然存在,我認爲問題出自這部分日誌(0612:28:20.383:E/AndroidRuntime 3861):在com.ipssum.coconal.Materiales.onItemSelected(Materiales.java:61))到最後,但我無法解決它,再次感謝 –

+0

你可以發佈Database.open()方法 – spezzino

+0

謝謝你修正了問題就在那裏,而不是實現可寫數據庫a有一個可讀的數據庫,感謝您的幫助 –

0

從跟蹤它看起來像你有創建表語句本身的問題...請清理create table語句與正確間距。

相關問題