Я пытаюсь создать базу данных и вставить значения в таблицу. но этот код не работает, может кто-нибудь мне помочь. спасибо заранее.
package com.bookshop;
import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.widget.AutoCompleteTextView;
import android.database.sqlite.SQLiteDatabase;
public class BookShop extends Activity {
private AutoCompleteTextView txttitle;
private AutoCompleteTextView txtauthor;
private AutoCompleteTextView txtisbn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}
private void initControls()
{
txttitle = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextViewtitle);
txtauthor = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextViewauthor);
txtisbn = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextViewisbn);
}
public void onsubmit(View view) {
//txttitle.setText(ValueOf(txtauthor)+ ValueOf(txtisbn));
// prepare the alert box
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
// set the message to display
alertbox.setMessage("Tittle : " + "" +(txttitle).getText()+"\n"+ "Author : "+"" + (txtauthor).getText()+"\n" + "ISBN : " +""+ (txtisbn).getText());
// add a neutral button to the alert box and assign a click listener
alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// the button was clicked
Toast.makeText(getApplicationContext(), "OK button clicked", Toast.LENGTH_LONG).show();
}
});
// show it
alertbox.show();
databaseacess();
}
public void databaseacess()
{
SQLiteDatabase db;
db = openOrCreateDatabase(
"BookShop.db"
, SQLiteDatabase.CREATE_IF_NECESSARY
, null
);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String CREATE_TABLE_BookShop =
"CREATE TABLE bookshop ("
//+"id, INTEGER PRIMARY KEY AUTOINCREMENT"
+"title TEXT"
+"author TEXT"
+"isbn);";
db.execSQL(CREATE_TABLE_BookShop);
ContentValues values = new ContentValues();
values.put("title",(txttitle).getText().toString());
values.put("author",(txtauthor).getText().toString());
values.put("isbn",(txtisbn).getText().toString());
try {
db.insertOrThrow("bookshop", null, values );
} catch (Exception e) {
//catch code
}
}
public void onclear(View view) {
txttitle.setText("");
txtauthor.setText("");
txtisbn.setText("");
}
}