- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 android 上为 SQlite 数据库创建一个表。该表有 5 列,Int id、URL 链接、String 标题、String 描述和 Date 日期。
为了构建我的代码,我一直在使用 this和 this作为引用,但都没有显示如何向游标添加除 String 之外的任何内容。
这是我的代码:
public class Chapter {
final SimpleDateFormat FORMATTER =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
private String title;
private URL link;
private String description;
private Date date;
private int id;
//Constructor for table includes ID.
public Chapter(int id, URL link, String title, String description, Date date) {
this.id = id;
this.link = link;
this.title = title;
this.description = description;
this.date = date;
}
//Empty Constructor
public Chapter() {
// TODO Auto-generated constructor stub
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title.trim();
}
// getters and setters omitted for brevity
public URL getLink() {
return link;
}
public void setLink(String link) {
try {
this.link = new URL(link);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description.trim();
}
public String getDate() {
return FORMATTER.format(this.date);
}
public void setDate(String date) {
// pad the date if necessary
while (!date.endsWith("00")){
date += "0";
}
date = "";
try {
this.date = FORMATTER.parse(date.trim());
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public Chapter copy(){
Chapter copy = new Chapter();
copy.title = title;
copy.link = link;
copy.description = description;
copy.date = date;
return copy;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Title: ");
sb.append(title);
sb.append('\n');
sb.append("Date: ");
sb.append(this.getDate());
sb.append('\n');
sb.append("Link: ");
sb.append(link);
sb.append('\n');
sb.append("Description: ");
sb.append(description);
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((date == null) ? 0 : date.hashCode());
result = prime * result
+ ((description == null) ? 0 : description.hashCode());
result = prime * result + ((link == null) ? 0 : link.hashCode());
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Chapter other = (Chapter) obj;
if (date == null) {
if (other.date != null)
return false;
} else if (!date.equals(other.date))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (link == null) {
if (other.link != null)
return false;
} else if (!link.equals(other.link))
return false;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
public int compareTo(Chapter another) {
if (another == null) return 1;
// sort descending, most recent first
return another.date.compareTo(date);
}
public int getId() {
// TODO Auto-generated method stub
return id;
}
public void setId(int parseInt) {
// TODO Auto-generated method stub
this.id = id;
}
public void setImage(String string) {
// TODO Auto-generated method stub
}
和我的助手类:
public class ChapterSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "chaptertable";
private static final int DATABASE_VERSION = 1;
// Database table
public static final String TABLE_CHAPTER = "Chapter";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_LINK = "link";
public static final String COLUMN_TITLE = "title";
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_PUBDATE = "pubdate";
public static final String COLUMN_IMAGEID = "imageid";
// Database creation SQL statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_CHAPTER
+ "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_LINK + " text not null, "
+ COLUMN_TITLE + " text not null,"
+ COLUMN_DESCRIPTION + " text not null"
+ COLUMN_PUBDATE + " text not null,"
+ COLUMN_IMAGEID + " text not null,"
+ ");";
public ChapterSQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Method is called during creation of the database
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
// Method is called during an upgrade of the database,
// e.g. if you increase the database version
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHAPTER);
// Create tables again
onCreate(db);
}
/**
* All CRUD(Create, Read, Update, Delete) Operations
*/
// Adding new contact
void addContact(Chapter chapter) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_ID, chapter.getId()); // Chapter ID
values.put(COLUMN_LINK, chapter.getLink()); // Chapter Link
values.put(COLUMN_TITLE, chapter.getTitle()); // Chapter Title
values.put(COLUMN_DESCRIPTION, chapter.getDescription()); // Chapter Description
values.put(COLUMN_PUBDATE, chapter.getDate()); // Chapter Date
//values.put(COLUMN_IMAGEID, chapter.getImage()); // Chapter Image
// Inserting Row
db.insert(TABLE_CHAPTER, null, values);
db.close(); // Closing database connection
}
// Getting single contact
Chapter getChapter(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CHAPTER, new String[] { COLUMN_ID,
COLUMN_ID, COLUMN_LINK }, COLUMN_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Chapter chapter = new Chapter(Integer.parseInt(cursor.getString(0)), cursor.getURL(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
// return contact
return chapter;
}
// Getting All Contacts
public List<Chapter> getAllContacts() {
List<Chapter> chapterList = new ArrayList<Chapter>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_CHAPTER;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Chapter chapter = new Chapter();
chapter.setId(Integer.parseInt(cursor.getString(0)));
chapter.setLink(cursor.getURL(1));
chapter.setTitle(cursor.getString(2));
chapter.setDescription(cursor.getString(3));
chapter.setDate(cursor.getString(4));
//chapter.setImage(cursor.getString(5));
// Adding chapter to list
chapterList.add(chapter);
} while (cursor.moveToNext());
}
// return contact list
return chapterList;
}
// Updating single contact
public int updateContact(Chapter chapter) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_ID, chapter.getId());
values.put(COLUMN_LINK, chapter.getLink());
values.put(COLUMN_TITLE, chapter.getTitle());
values.put(COLUMN_DESCRIPTION, chapter.getDescription());
values.put(COLUMN_PUBDATE, chapter.getDate());
//values.put(COLUMN_IMAGEID, chapter.getImage());
// updating row
return db.update(TABLE_CHAPTER, values, COLUMN_ID + " = ?",
new String[] { String.valueOf(chapter.getId()) });
}
// Deleting single contact
public void deleteContact(Chapter chapter) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CHAPTER, COLUMN_ID + " = ?",
new String[] { String.valueOf(chapter.getId()) });
db.close();
}
// Getting contacts Count
public int getChaptersCount() {
String countQuery = "SELECT * FROM " + TABLE_CHAPTER;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
我在链接的 values.put 行和 Chapter chapter = new Chapter... 行上遇到编译错误。
最佳答案
您需要在 copy()
方法中使用 setter 方法设置属性,例如:
public Chapter copy(){
Chapter copy = new Chapter();
copy.setTitle(this.title);
copy.setLink(this.link);
copy.setDescription(this.description);
copy.setDate(this.date);
return copy;
}
关于java - 未定义的构造函数 SQLite 游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12078565/
注意:根据 ECMAScript5.1, section 15.1.1.3 , window.undefined 是只读的。 现代浏览器正确地实现了这一点。例如:Safari 5.1、Firefox
我用谷歌搜索,检查了所有常见的响应。这些脚本似乎顺序正确(它们在 the demo 中以相同的顺序工作)但由于某种原因,当我尝试实现它时,我得到了错误。 我有一个 paste bin用我完整的页面代码
我有以下代码: simpleExample.html: Simple example Open the Console. js/simpleExampleJS.
所以我对 typescript 很陌生。 这是我的 tsconfig.json 文件的样子, 我什至不知道那些“例子”是从哪里来的 这是我在浏览器中遇到的错误 这是我的 package.json 最佳
我被 TypeScript 错误困住了: Failed to compile. undefined TypeScript error in undefined(undefined,undefined)
我已将 onlcick 事件附加到表单的提交按钮以覆盖默认的 POST 请求,但在使其正常工作时遇到了一些问题。 我想要的是点击添加到购物车的商品,但只显示模式确认而不刷新页面。 这段代码在我的静态示
我已经完成了这个link .但是给定的解决方案并没有解决我的问题。所有经验丰富的人都建议使用 getActivty().getApplicationContext()。但我使用的是普通类(class)
我有一个应用程序,其中 webpack 配置为模块 bundler ,babel 作为我的 js 编译器。全部都在 Node 引擎上。我设置当我运行 npm run dev 时,将会发生以下流程: w
我正在尝试在浏览器中呈现网址的 JSON 数据,但它在 div 中显示为 undefined, undefined .当我将其响应放入console.log时对象及其数据出现,因此它出现在控制台和浏览
为什么我会收到 Cannot invoke an object which is possibly 'undefined'即使在我检查了 func 之后,Typescript 也会出错引用不是未定义的
我想使用airbnb的eslint修改我的代码结构。我已遵循 eslint-config-airbnb 中给出的说明。启动命令后npm run lint,结果由 'fetch' is not Defi
这个问题在这里已经有了答案: What is the consequence of this bit of javascript? (4 个答案) 关闭 9 年前。 我看到一些 jQuery 脚本嵌
我一直收到这个 pouchDB 错误,我不知道这是怎么回事。 Error: connect ENFILE 127.0.0.1:5984 - Local (undefined:undefined)
import os from os.path import abspath, dirname import sys # Set up django project_dir = abspath(dirn
在 javascript 中,要检查变量是否从未创建过,我们只需执行 if (typeof MyVariable !== "undefined"){ ... } 我想知道如何在 CoffeeScrip
我正在尝试编译 FreeLing,它使用 CMake 来检测 Boost。这是负责它的代码: find_package(Boost COMPONENTS regex filesystem thre
我收到“JQUERY 未定义”错误。你有什么想法吗(代码如下)。 $(document).ready(function() { window.print();
无论我是否将 jQuery $.ajax 调用放入 $(document).ready(function() { 中,我都会收到此错误。这是在 ASP.NET MVC .cshtml 文件上.
我正在构建的网站上遇到问题,但数据表不存在加载(在服务器上)但在本地主机(xamp)上工作正常。 Firefox 会抛出错误“$ 未定义”。 我用谷歌搜索了这些错误,我发现一个 friend 的解决方
当我在 $(document).ready 之前明确包含 jQuery 库时,我无法弄清楚为什么它仍然无法识别 jQuery 语法
我是一名优秀的程序员,十分优秀!