gpt4 book ai didi

android.database.sqlite.SQLiteException 靠近 DATABASE_TABLE_NAME 语法错误(代码 :1) while compiling organizationSetup

转载 作者:行者123 更新时间:2023-12-02 05:15:46 27 4
gpt4 key购买 nike

我正在开发一个Android应用程序,其中我创建了一个 Activity ,在该 Activity 中我一直在//Session For select_category page in Activity.java 行下方显示两个 TextView :

以前我已经在这个 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;

} }

我不明白代码中的错误是什么(获取的数据)没有显示在 TextView 上。请尽快提供答案来帮助我解决这个问题。

最佳答案

无法说出您的问题是什么,因为您的描述令人困惑,但如果您的错误是

编译organizationSetup时在DATABASE_TABLE_NAME附近出现android.database.sqlite.SQLiteException语法错误(代码:1)

尝试在表名后面添加一个空格。您的括号与表名称相接触。

关于android.database.sqlite.SQLiteException 靠近 DATABASE_TABLE_NAME 语法错误(代码 :1) while compiling organizationSetup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20717863/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com