- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我创建了一个包含两个表的 android 数据库。第二个尚未初始化,但对于第一个我收到此错误。
这是我的日志。
02-23 01:55:41.494 855-855/tubapps.budgetdatabase E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{tubapps.budgetdatabase/tubapps.budgetdatabase.MainActivity}: android.database.sqlite.SQLiteException: near "create_income_table": syntax error (code 1): , while compiling: create_income_table income(_id INTEGER PRIMARY KEY AUTOINCREMENT, income_amount TEXT NOT NULL, income_payer TEXT NOT NULL, income_date TEXT NOT NULL, income_category TEXT NOT NULL, income_payments TEXT NOT NULL);
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "create_income_table": syntax error (code 1): , while compiling: create_income_table income(_id INTEGER PRIMARY KEY AUTOINCREMENT, income_amount TEXT NOT NULL, income_payer TEXT NOT NULL, income_date TEXT NOT NULL, income_category TEXT NOT NULL, income_payments TEXT NOT NULL);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
at tubapps.budgetdatabase.DBHelper.onCreate(DBHelper.java:55)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at tubapps.budgetdatabase.SQLController.open(SQLController.java:21)
at tubapps.budgetdatabase.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
这是我的 dbhelper。
public class DBHelper extends SQLiteOpenHelper {
// TABLE INFORMATTION
public static final String TABLE_INCOME = "income";
public static final String INCOME_ID = "_id";
public static final String INCOME_AMOUNT = "income_amount";
public static final String INCOME_PAYER = "income_payer";
public static final String INCOME_DATE = "income_date";
public static final String INCOME_CATEGORY = "income_category";
public static final String INCOME_PAYMENTS = "income_payments";
public static final String TABLE_EXPENSE = "expense";
public static final String EXPENSE_ID = "_id";
public static final String EXPENSE_AMOUNT = "expense_amount";
public static final String EXPENSE_PAYEE = "expense_payee";
public static final String EXPENSE_DATE = "expense_date";
public static final String EXPENSE_CATEGORY = "expense_category";
public static final String EXPENSE_PAYMENTS = "expense_payments";
// DATABASE INFORMATION
static final String DB_NAME = "BUDGET.DB";
static final int DB_VERSION = 1;
// TABLE CREATION STATEMENT
private static final String CREATE_INCOME_TABLE = "createIncomeTable "
+ TABLE_INCOME + "(" + INCOME_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ INCOME_AMOUNT + " TEXT NOT NULL, "
+ INCOME_PAYER + " TEXT NOT NULL, "
+ INCOME_DATE + " TEXT NOT NULL, "
+ INCOME_CATEGORY + " TEXT NOT NULL, "
+ INCOME_PAYMENTS + " TEXT NOT NULL);";
private static final String CREATE_EXPENSE_TABLE = "createExpenseTable "
+ TABLE_EXPENSE + "(" + EXPENSE_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ EXPENSE_AMOUNT + " TEXT NOT NULL, "
+ EXPENSE_PAYEE + " TEXT NOT NULL, "
+ EXPENSE_DATE + " TEXT NOT NULL, "
+ EXPENSE_CATEGORY + " TEXT NOT NULL, "
+ EXPENSE_PAYMENTS + " TEXT NOT NULL);";
public DBHelper(Context context) {
super(context, DB_NAME, null,DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_INCOME_TABLE);
db.execSQL(CREATE_EXPENSE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_INCOME);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_EXPENSE);
onCreate(db);
}
}
这是我的 sqlcontroller。
public class SQLController {
private DBHelper dbhelper;
private Context ourcontext;
private SQLiteDatabase database;
public SQLController(Context c) {
ourcontext = c;
}
public SQLController open() throws SQLException {
dbhelper = new DBHelper(ourcontext);
database = dbhelper.getWritableDatabase();
return this;
}
public void close() {
dbhelper.close();
}
public void insertIncomeData(String incomeAmount, String incomePayer, String incomeDate,
String incomeCategory, String incomePayments) {
ContentValues cv = new ContentValues();
cv.put(DBHelper.INCOME_AMOUNT, incomeAmount);
cv.put(DBHelper.INCOME_PAYER, incomePayer);
cv.put(DBHelper.INCOME_DATE, incomeDate);
cv.put(DBHelper.INCOME_CATEGORY, incomeCategory);
cv.put(DBHelper.INCOME_PAYMENTS, incomePayments);
database.insert(DBHelper.TABLE_INCOME, null, cv);
}
public void insertExpenseData(String expenseAmount, String expensePayee, String expenseDate,
String expenseCategory, String expensePayments) {
ContentValues cv = new ContentValues();
cv.put(DBHelper.EXPENSE_AMOUNT, expenseAmount);
cv.put(DBHelper.EXPENSE_PAYEE, expensePayee);
cv.put(DBHelper.EXPENSE_DATE, expenseDate);
cv.put(DBHelper.EXPENSE_CATEGORY, expenseCategory);
cv.put(DBHelper.EXPENSE_PAYMENTS, expensePayments);
database.insert(DBHelper.TABLE_EXPENSE, null, cv);
}
//Getting Cursor to read data from table
public Cursor readIncomeData() {
String[] allColumns = new String[] { DBHelper.INCOME_ID,
DBHelper.INCOME_AMOUNT, DBHelper.INCOME_PAYER, DBHelper.INCOME_DATE,
DBHelper.INCOME_CATEGORY, DBHelper.INCOME_PAYMENTS };
Cursor c = database.query(DBHelper.TABLE_INCOME, allColumns, null,
null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
//Getting Cursor to read data from table
public Cursor readExpenseData() {
String[] allColumns = new String[] { DBHelper.EXPENSE_ID,
DBHelper.EXPENSE_AMOUNT, DBHelper.EXPENSE_PAYEE, DBHelper.EXPENSE_DATE,
DBHelper.EXPENSE_CATEGORY, DBHelper.EXPENSE_PAYMENTS };
Cursor c = database.query(DBHelper.TABLE_EXPENSE, allColumns, null,
null, null, null, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
//Updating record data into table by id
public int updateIncomeData(long incomeID, String newIncomeAmount, String newIncomePayer, String newIncomeDate,
String newIncomeCategory, String newIncomePayments) {
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(DBHelper.INCOME_AMOUNT, newIncomeAmount);
cvUpdate.put(DBHelper.INCOME_PAYER, newIncomePayer);
cvUpdate.put(DBHelper.INCOME_DATE, newIncomeDate);
cvUpdate.put(DBHelper.INCOME_CATEGORY, newIncomeCategory);
cvUpdate.put(DBHelper.INCOME_PAYMENTS, newIncomePayments);
int i = database.update(DBHelper.TABLE_INCOME, cvUpdate,
DBHelper.INCOME_ID + " = " + incomeID, null);
return i;
}
public int updateExpenseData(long expenseID, String newExpenseAmount, String newExpensePayer, String newExpenseDate,
String newExpenseCategory, String newExpensePayments) {
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(DBHelper.EXPENSE_AMOUNT, newExpenseAmount);
cvUpdate.put(DBHelper.EXPENSE_PAYEE, newExpensePayer);
cvUpdate.put(DBHelper.EXPENSE_DATE, newExpenseDate);
cvUpdate.put(DBHelper.EXPENSE_CATEGORY, newExpenseCategory);
cvUpdate.put(DBHelper.EXPENSE_PAYMENTS, newExpensePayments);
int i = database.update(DBHelper.TABLE_EXPENSE, cvUpdate,
DBHelper.EXPENSE_ID + " = " + expenseID, null);
return i;
}
// Deleting record data from table by id
public void deleteIncomeData(long incomeID) {
database.delete(DBHelper.TABLE_INCOME, DBHelper.INCOME_ID + "="
+ incomeID, null);
}
public void deleteExpenseData(long expenseID) {
database.delete(DBHelper.TABLE_EXPENSE, DBHelper.EXPENSE_ID + "="
+ expenseID, null);
}
}
这是我的主要 Activity 。
public class MainActivity extends ActionBarActivity {
ListView lv;
SQLController dbcon;
TextView incomeID_tv, incomePayer_tv, incomeAmount_tv;
TextView incomeDate_tv, incomeCategory_tv, incomePayments_tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbcon = new SQLController(this);
dbcon.open();
lv = (ListView) findViewById(R.id.incomeList_id);
Cursor cursor = dbcon.readIncomeData();
String[] from = new String[] { DBHelper.INCOME_ID, DBHelper.INCOME_AMOUNT, DBHelper.INCOME_PAYER,
DBHelper.INCOME_DATE, DBHelper.INCOME_CATEGORY, DBHelper.INCOME_PAYMENTS};
int[] to = new int[] { R.id.income_id, R.id.income_amount, R.id.income_payer, R.id.income_date,
R.id.income_category, R.id.income_payments};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
MainActivity.this, R.layout.income_entry, cursor, from, to);
adapter.notifyDataSetChanged();
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
incomeID_tv = (TextView) view.findViewById(R.id.income_id);
incomeAmount_tv = (TextView) view.findViewById(R.id.income_amount);
incomePayer_tv = (TextView) view.findViewById(R.id.income_payer);
incomeDate_tv = (TextView) view.findViewById(R.id.income_date);
incomeCategory_tv = (TextView) view.findViewById(R.id.income_category);
incomePayments_tv = (TextView) view.findViewById(R.id.income_payments);
String incomeID = incomeID_tv.getText().toString();
String incomeAmount = incomeAmount_tv.getText().toString();
String incomePayer = incomePayer_tv.getText().toString();
String incomeDate = incomeDate_tv.getText().toString();
String incomeCategory = incomeCategory_tv.getText().toString();
String incomePayments = incomePayments_tv.getText().toString();
Intent modify_intent = new Intent(getApplicationContext(),
IncomeEdit.class);
modify_intent.putExtra("incomeID", incomeID);
modify_intent.putExtra("newIncomeAmount", incomeAmount);
modify_intent.putExtra("newIncomePayer", incomePayer);
modify_intent.putExtra("newIncomeDate", incomeDate);
modify_intent.putExtra("newIncomeCategory", incomeCategory);
modify_intent.putExtra("newIncomePayments", incomePayments);
startActivity(modify_intent);
}
});
}
DBHelper 的第 55 行是这样的:
db.execSQL(CREATE_INCOME_TABLE);
SQLController 的第 21 行是这样的:
database = dbhelper.getWritableDatabase();
MainActivity 的第 29 行是这样的:
dbcon.open();
我在其他问题中看到它可能来自表名。它们之间有空格,但在我更改它之后,它仍然无法正常工作。
最佳答案
你正在执行命令:
create_income_table income(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
income_amount TEXT NOT NULL,
income_payer TEXT NOT NULL,
income_date TEXT NOT NULL,
income_category TEXT NOT NULL,
income_payments TEXT NOT NULL
);
将 create_income_table
替换为 CREATE TABLE
。您需要执行此 SQL:
CREATE TABLE income(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
income_amount TEXT NOT NULL,
income_payer TEXT NOT NULL,
income_date TEXT NOT NULL,
income_category TEXT NOT NULL,
income_payments TEXT NOT NULL
);
关于android.database.sqlite.SQLiteException : near ": syntax error (code 1): , 编译时:android 编程错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665039/
code
正常吗?
我刚刚开始使用 YARD 来记录我的 Rails 应用程序。我没有指定任何特定的标记处理程序,但我希望 `code` 会转换为 code,但这似乎没有发生。这是正常行为吗?我是否必须添加一些额外的选项
什么是Code-Server 首先程序员朋友们肯定都用过来自微软的VS Code 这款轻量而又高级的编辑器,拥有丰富的插件库,支持各种语言编译运行。而本文介绍的Code-Server就是coder 公
我是一名高中生,今年开始学习汇编。 我目前正在制作 Pacman 克隆作为我的最终项目。 我遇到的唯一问题是我的代码很大,*.exe 文件几乎有 64KB。 所以我的问题是,如果我转向模型介质,我需要
锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 挑战 按字符计数绘制 Code 39 条码的 ASCII 表示的最短代码。 维基百科关于代码 3
我正在开发 VS 代码的扩展(使用 javascript)。现在我需要安装 VS Code 的路径。 windows有一种方法: var child = require('child_process'
[Windows 10] 我在自定义目录中安装了“Microsoft VS Code(用户设置)”,每当我尝试更新它时,都会显示: 然后这个 Log Info Dec 23 11:42:40.673
我正在尝试更新我的 VS 代码,但收到一条错误消息:由于防病毒软件和/或进程失控,更新可能会失败。 附加了一个来 self 的用户的日志文件,但我不确定要检查什么。我对计算机和编程还是个新手。 最佳答
几天前我安装了 Kali Linux。我正在尝试使用 Code-OSS 而不是 VSCode,因为最新版本的 Kali 没有安装普通版本所需的库。 如果我尝试使用 code-oss . 或 code
我正在从 Atom 迁移到 VS Code,因为这似乎是当今所有酷 child 都在使用的东西。 在 atom 中,我能够如图所示突出显示当前行号(装订线中的蓝色突出显示)。 有没有办法在 VS Co
我试图找到一个明确的 G 代码语法规范,而不是单个 G 代码的含义,我无处不在的规范,我的意思是详细的语法规范,目的是编写解析器。 我编写解析器没有问题,我只是在寻找语法规范,例如。我知道您不必总是为
我想在 VS Code (Windows) 中使用 Fira Code,并且已经按照 instructions 中的说明配置了字体。 。不知何故,字体看起来很模糊。我该如何解决这个问题? "edito
这个问题已经有答案了: How can I navigate back to the last cursor position in Visual Studio Code? (16 个回答) 已关闭
如何选择当前单词,即插入符号所在的位置。 注意:我正在寻找 Visual Studio Code(VS Code)(文本编辑器)的快捷方式,而不是 Visual Studio IDE。 最佳答案 在
我需要在 VS Code 中安装 flutter 但在安装扩展中,我有这个错误 Unable to install 'Dart-Code.flutter'; there is no available
memberData
有什么区别
{@code memberData} 和有什么区别?和 memberData在 JavaDoc 中 最佳答案 有两个主要区别: {@code ...}更简洁:更易于阅读(和输入)。 {@code ..
我有这样一个字符串: Here is my code sample, its not too great: [CODE] [/CODE] I hope you enjoy. 现在我想用 highli
在 VS Code 中,我有一个少于 50 个文件的 Vue 项目,但是在运行开发服务器时 VS Code 抛出 Error: ENOSPC: System limit for number of f
Source Code Pro 如何在 VSC 中使用 ExtraLight ~? 似乎以下不起作用...... 我确定我有字体。 Source Code Pro ExtraLight 最佳答案 编辑
我对 Visual Studio Code 很陌生。我正在尝试调试一个已经存在的应用程序,我已经通过 Git 克隆了它。我的文件都没有被修改。我已经下载了微软扩展“C# for Visual Stud
Visual Code VS Visual Studio Code Insider 我还是不明白这两者有什么区别,难道其中一个是新功能的试用版吗? 最佳答案 Visual Studio Code In
我是一名优秀的程序员,十分优秀!