异常“表...没有列名...”(Exception “table… has no column named…”)
我在尝试插入名为“my_card”的表时遇到了一个非常奇怪的错误。
这些是我在一个单独的界面中定义的一些常量:
//tables name public static final String TABLE_MY_CARD= "my_card" ; public static final String TABLE_MY_CONTACTS = "my_contacts" ; // Columns public static final String NAME = "name" ; public static final String PHONE = "phone" ; public static final String EMAIL = "email"; public static final String FACEBOOK = "facebook"; public static final String WEBSITE = "web"; public static final String MAJOR = "major"; public static final String ULINK = "ulink";
之后,我有一个扩展SQLiteOpenHelper的类,有2个函数。 最重要的是第一个创建由参数给出的表格。
public class MySQLite_methods extends SQLiteOpenHelper implements Tables { private static final String DATABASE_NAME = "my_database.db" ; private static final int DATABASE_VERSION = 1; private String TABLE_NAME; /** Create a helper object for the Events database */ public MySQLite_methods (Context ctx, String table_name) { super(ctx, DATABASE_NAME, null, DATABASE_VERSION); this.TABLE_NAME = table_name; } @Override public void onCreate(SQLiteDatabase db) { String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT NOT NULL," + PHONE + " TEXT NOT NULL,"+ EMAIL + " TEXT NOT NULL,"+ FACEBOOK + " TEXT,"+ WEBSITE + " TEXT,"+ MAJOR + " TEXT NOT NULL,"+ ULINK + " TEXT NOT NULL" + ");" ; db.execSQL(sql); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } }
最后,在我的活动中,按下按钮保存后,将创建一个类的实例,并且必须将一些EditText-s的值插入到数据库中:
MySQLite_methods mysql = new MySQLite_methods (context, TABLE_MY_CARD); Log.d("geo", "before getWr...."); // getting the database.. SQLiteDatabase db = mysql.getWritableDatabase(); // creating an object of type ContentValues which represents the record i am gonna add into the DB ContentValues values = new ContentValues(); values.put(NAME, name.getText().toString()); values.put(PHONE, phone.getText().toString()); values.put(EMAIL, email.getText().toString()); values.put(FACEBOOK, facebook.getText().toString()); values.put(WEBSITE, website.getText().toString()); values.put(MAJOR, major.getText().toString()); values.put(ULINK, ulink.getText().toString()); Log.d("geo", "before insert"); // inserting data db.insertOrThrow(TABLE_MY_CARD, null, values);
在插入时它给出了这个例外:
“android.database.sqlite.SQLiteException:表my_card没有列名为web ....”
我一遍又一遍地检查了输入错误,但没有...所以我现在不知道该怎么办......任何想法? 谢谢
I am facing a really weird error,while trying to insert into a table called "my_card".
These are some constants I defined in a separate interface:
//tables name public static final String TABLE_MY_CARD= "my_card" ; public static final String TABLE_MY_CONTACTS = "my_contacts" ; // Columns public static final String NAME = "name" ; public static final String PHONE = "phone" ; public static final String EMAIL = "email"; public static final String FACEBOOK = "facebook"; public static final String WEBSITE = "web"; public static final String MAJOR = "major"; public static final String ULINK = "ulink";
After that I have a class which extends SQLiteOpenHelper, with 2 functions. The most important is the first one which creates the table given by a parameter.
public class MySQLite_methods extends SQLiteOpenHelper implements Tables { private static final String DATABASE_NAME = "my_database.db" ; private static final int DATABASE_VERSION = 1; private String TABLE_NAME; /** Create a helper object for the Events database */ public MySQLite_methods (Context ctx, String table_name) { super(ctx, DATABASE_NAME, null, DATABASE_VERSION); this.TABLE_NAME = table_name; } @Override public void onCreate(SQLiteDatabase db) { String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT NOT NULL," + PHONE + " TEXT NOT NULL,"+ EMAIL + " TEXT NOT NULL,"+ FACEBOOK + " TEXT,"+ WEBSITE + " TEXT,"+ MAJOR + " TEXT NOT NULL,"+ ULINK + " TEXT NOT NULL" + ");" ; db.execSQL(sql); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } }
And finally, in my activity, after pressing a button for save, an instance of the class will be created and the values of some EditText-s have to be inserted into the database:
MySQLite_methods mysql = new MySQLite_methods (context, TABLE_MY_CARD); Log.d("geo", "before getWr...."); // getting the database.. SQLiteDatabase db = mysql.getWritableDatabase(); // creating an object of type ContentValues which represents the record i am gonna add into the DB ContentValues values = new ContentValues(); values.put(NAME, name.getText().toString()); values.put(PHONE, phone.getText().toString()); values.put(EMAIL, email.getText().toString()); values.put(FACEBOOK, facebook.getText().toString()); values.put(WEBSITE, website.getText().toString()); values.put(MAJOR, major.getText().toString()); values.put(ULINK, ulink.getText().toString()); Log.d("geo", "before insert"); // inserting data db.insertOrThrow(TABLE_MY_CARD, null, values);
At the moment of the insert it gives this exception:
"android.database.sqlite.SQLiteException: table my_card has no column named web ...."
I checked over and over again for typo mistakes, but none... So i dont know what to do now... Any idea? Thank you
原文:https://stackoverflow.com/questions/8197396
最满意答案
我决定在父元素中添加ng-repeat语句,从而需要明确定义范围。 它现在写道:
<select ng-model="loan.BorrowerId" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) for person in Persons" class="form-control"></select>{{BorrowerId}} <select multiple ng-model="loan.CoBorrowerIds" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) disable when (person.Id==loan.BorrowerId) for person in Persons" class="form-control"></select>
......它工作正常。 这可能是一个错误,或者我的思维差。 然而,对于它的价值,有答案!
I decided to add a ng-repeat statement to the parent element, creating a need to explicitly define the scope. It now reads:
<select ng-model="loan.BorrowerId" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) for person in Persons" class="form-control"></select>{{BorrowerId}} <select multiple ng-model="loan.CoBorrowerIds" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) disable when (person.Id==loan.BorrowerId) for person in Persons" class="form-control"></select>
...and it works fine. It may be a bug, or my poor thinking. However, for what it's worth, there's the answer!
相关问答
更多-
在ngOptions中重复(Duplicates in ngOptions)[2021-07-15]
这是1.4.8之前1.4.x的已知错误,您可以检查问题 。 如果你必须使用angularjs 1.4.7版本,那么你可以用ng-show代替ng-if 你可以从angularjs github找到更新日志和错误 It is a known bug for 1.4.x before 1.4.8 you can check issue. If you have to use angularjs 1.4.7 version then you can use ng-show instead ng-if You ca ... -
您想在ng-options过滤器。 此过滤器应占用您的部门阵列并删除您不需要的部门。 因此,您需要将该部门或至少其索引传递给过滤器功能 ng-options=".. as ... for .. in depts | filterFunction:dept" 请参阅在ng-options上使用过滤器以更改显示的值 You want to put a filter in your ng-options. This filter should take your array of departments and ...
-
AngularJS orderBy在ngOptions中没有跟踪轨迹?(AngularJS orderBy does not work with track by in ngOptions?)[2023-05-08]
为了使用带有过滤器的track by需要在过滤器之后添加track by表达式的track by 。 改为: user.id as user.name for user in users | orderBy: 'name' track by user.id ngRepeat的文档在“参数”部分提到了这一点,具体来说是: 在指定跟踪表达式之前,应将过滤器应用于表达式。 和 例如: 项目中的项目| filter:item.id中的searchText跟踪可以用于将过滤器与跟踪表达式结合使用的项目。 In or ... -
Angularjs - ngOptions使'group by'-group可选(Angularjs - ngOptions make 'group by'-group selectable)[2022-02-06]
我找到了这个主题: 在HTML -
AngularJS select:基于当前表单状态限制ngOptions(AngularJS select: limiting ngOptions based on a current form state)[2022-07-14]
简单的修复方法是在控制器中添加一个观察器 $scope.$watch('unit', function(oldValue, newValue){ $scope.groupby = 0; }); 请参阅此答案以获得解释。 The simple fix will be add a watcher in the controller $scope.$watch('unit', function(oldValue, newValue){ $scope.groupby = 0; }); Pleas ... -
我不知道任何版本的Angular都允许您在没有先创建模块的情况下创建控制器。 无论如何,实例化模块并注册控制器可以解决您的问题。 jsbin 将其添加到html中的应用程序decalartion中: ng-app="app" 修改你的脚本: angular.module('app', []) // this creates a module function MyController () { ... } // register controller to module angular.module( ...
-
我决定在父元素中添加ng-repeat语句,从而需要明确定义范围。 它现在写道: {{BorrowerId}}
AngularJS 1.5 ngOptions显示普通数组的比较(AngularJS 1.5 ngOptions Comparison for Displaying a Plain Array)[2022-09-13]
没有找到使用track by的解决方案,但是Ang的AngularJS文档有一个使用解析器和格式化程序的解决方案,所以我可以摆脱在问题中使用hack。 我调整了一下,所以如果键是一个字符串,它将不管它,否则它转换它,这似乎工作。 任何批评或问题,我没有看到请评论,否则希望这有助于某人。 (function () { 'use strict'; /** * Binds a select field to a non-string value via ngModel parsing ...Handlebar语法表示JavaScript表达式,或者特定的Angular表达式 。 使用把手内部的把手没有意义,因为你已经告诉编译器你正在从HTML切换到JavaScript。 话虽如此,你可以在没有内部把手的情况下重写你的表达: {{ (userLanguage ? userLanguage.chosenLanguage : 'LB_CHOOSE_LANGUAGE') | translate }} Handlebar syntax implies a JavaScript expression, ...我总是在ng-options中使用别名“as”:相关文章
更多- table-Oceanus配置说明
- Guava集合工具类-Table接口映射处理
- Lua table(表、数组、字典)
- Lua 元表(Metatable)改变table的行为
- Guava学习笔记:Guava新集合-Table等
- mybatis There is no getter for property named 'xx' in 'class java.lang.String
- 求教一个 table的css
- java Exception异常处理实例
- Java 异常处理
- div中table100%宽度的浏览器兼容性问题
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。