我正在開發一個android應用程序,在該應用程序中創建了一個活動,在該活動中我保持顯示的兩個文字視圖會話對於Activity.java中的select_category頁面:android.database.sqlite.SQLiteException在編譯organizationSetup時DATABASE_TABLE_NAME語法錯誤(代碼:1)
以前我已經在這個textview上設置了日期和時間,但是現在我從數據庫中獲取來自getMandaliName()方法的mandali名稱的值,並試圖保留這個textview,那麼它仍然顯示我設置的日期和時間。我不知道它爲什麼顯示先前在textview上設置的數據,而不是在textview上顯示提取的數據。 我Activity.java是在這裏:
package com.bis.localsale;
import java.security.PublicKey;
import com.bis.localsale.util.CommonUtil;
import com.bis.localsale.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class SelectCategory extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_category);
DBHelper db = new DBHelper(this);
Button btnMandaliName = (Button) findViewById(R.id.mandali_name);
final String mandali = db.getMandaliName();
System.out.println(mandali);
Toast.makeText(getApplicationContext(),mandali,
Toast.LENGTH_SHORT).show();
btnMandaliName.setText(mandali);
//Session For select_category page
TextView txtSession = (TextView) findViewById(R.id.txtSession);
txtSession.setText(mandali);
TextView textTime = (TextView) findViewById(R.id.txtTime);
textTime.setText(mandali);
DisplayMetrics dmAdmin =new DisplayMetrics();
WindowManager windowManager = (WindowManager) this.getSystemService(this.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
final EditText editTextLitre = (EditText) findViewById(R.id.edit_text_litre);
editTextLitre.setInputType(InputType.TYPE_CLASS_NUMBER);
final TextView tvwAmount = (TextView)findViewById(R.id.amount);
editTextLitre.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if(s.length()>0){
if(s.length()<5){
String text = String.valueOf(Float.valueOf(s.toString())*10);
tvwAmount.setText(text);
Toast.makeText(getApplicationContext(),
mandali,
Toast.LENGTH_SHORT).show();
}
else{
InputFilter[] FilterArray = new InputFilter[0];
FilterArray[0] = new InputFilter.LengthFilter(4);
editTextLitre.setFilters(FilterArray);
/*editTextLitre.setText(s.subSequence(0, 4));*/
}
}
else{
tvwAmount.setText("0");
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
Button btnSaveDetails = (Button) findViewById(R.id.btnSave);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.select_category_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.admin:
Intent intent1 = new Intent("com.example.localsale.Admin");
startActivity(intent1);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我的數據庫輔助類顯示下面
我DBHelper.java代碼是在這裏:
package com.bis.localsale;
import java.io.IOException;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBHelper extends SQLiteOpenHelper
{
private SQLiteDatabase db;
public static final String KEY_ROWID = "_id";
public static final String KEY_CREATED_USER = "createdUser";
public static final String KEY_CREATED_DATE = "createdDate";
public static final String KEY_LAST_MODIFIED_USER= "lastModifiedUser";
public static final String KEY_LAST_MODIFIED_DATE= "lastModifiedDate";
public static final String KEY_RECORD_STATUS = "recordStatus";
public static final String KEY_NAMEOFMANDALI = "nameOfMandali";
public static final String KEY_RATEOFCOW = "rateOfCow";
public static final String KEY_RATEOFBUFFALO = "rateOfBuffalo";
DBHelper DB = null;
private static final String DATABASE_NAME = "localsale.db";
private static final int DATABASE_VERSION = 1;
public static final String DATABASE_TABLE_NAME = "organizationSetup";
private static final String DATABASE_TABLE_CREATE = "CREATE TABLE "
+ DATABASE_TABLE_NAME
+ "("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "nameOfMandali TEXT NOT NULL, rateOfCow TEXT NOT NULL, rateOfBuffalo TEXT NOT NULL, createdUser TEXT NOT NULL, createdDate TEXT NOT NULL, lastModifiedUser TEXT NOT NULL, lastModifiedDate TEXT NOT NULL, recordStatus TEXT NOT NULL);";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_TABLE_CREATE);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_CREATE);
// Create tables again
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
public Cursor rawQuery(String string, String[] strings) {
// TODO Auto-generated method stub
return null;
}
public SQLiteDatabase open() {
SQLiteDatabase db = this.getWritableDatabase();
return db;
}
public Cursor getDetails(String text) throws SQLException {
Cursor mCursor = db.query(DATABASE_TABLE_NAME, new String[] {
KEY_ROWID, KEY_CREATED_USER, KEY_CREATED_DATE, KEY_LAST_MODIFIED_USER, KEY_LAST_MODIFIED_DATE,
KEY_RECORD_STATUS }, null, null, null, null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public void insert(String DATABASE_TABLE_NAME, Object object,
ContentValues values) {
// TODO Auto-generated method stub
}
@SuppressLint("NewApi")
public String getMandaliName(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(DATABASE_TABLE_NAME, new String[]
{ KEY_NAMEOFMANDALI}, null);
if (cursor != null)
cursor.moveToLast();
String mandaliName = cursor.getString(cursor.getColumnIndex(KEY_NAMEOFMANDALI));
Log.e("test", mandaliName);
return mandaliName;
}}
我不是得到的是代碼中的錯誤(取出數據)沒有顯示在文本視圖上。請通過儘快提供答案來幫助我。
你確定你的數據庫正確填充了嗎? –
顯示實際的錯誤信息。 –