基本上,我正在尝试显示listview的结果(使用QSLite创建)但是在CourseDetails类中提取listview的元素,产生了这个问题:
“描述资源路径位置类型 构造函数DBHelper(CourseDetails)未定义CourseDetails.java / MariposaTrainingMobile / src / com / mariposatraining / courses第31行Java问题“
我正在使用DBHelper类,但我不知道为什么程序发送给我错误,并且没有给出问题的解决方案,我的DBHelper类的代码是下一个:
public class DBHelper extends SQLiteOpenHelper{
private String sql;
SQLiteDatabase db;
public DBHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db)
{
// TODO Auto-generated method stub
String sql= " CREATE TABLE courses (" + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + " title TEXT, " + " instructor TEXT, " + " length TEXT, " + " rating TEXT, " + " topic TEXT, " + " subject TEXT, " + "description TEXT)";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS courses");
onCreate(db);
}
public void insertCourses()
{
db=getWritableDatabase();
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Enabling Freedom...', 'Instructor: Keith Savell', 'length: 60', 'Rating: 4.82', 'Topic: Creating a Prosthetic Environment ', 'Subject:Learn to evaluate and modify the environment to support our residents with cognitive impairment as they age in place.', 'Description: Residents with dementia and delirium are constantly assessing the environment, looking for clues to help them understand where they are, who others around them are, what they are supposed to be doing and what is expected of them.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Interdisciplinary Care Planning', 'Instructor: Keith Savell', 'length: 60', 'Rating: 4.7', 'Topic: Interdisciplinary Care Planning', 'Subject:Encourage the Interdisciplinary Treatment Team (IDT) to work as a team and view the Care Plan as a resident-centered collaborative effort to enhance the care and quality of resident life.', 'Description: Interdisciplinary Care Planning requires members of the Interdisciplinary Treatment Team (IDT) to view the Care Plan as a resident centered collaborative effort - rather than as a staff centered document. Learn how to utilize the Care Plan to truly function as a team - working together to enhance the care and quality of resident life.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Culture Change: Creating A Climate Of Care...', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Culture Change ', 'Subject:Learn to evaluate and modify the environment to support our residents with cognitive impairment as they age in place.', 'Description: Residents with dementia and delirium are constantly assessing the environment, looking for clues to help them understand where they are, who others around them are, what they are supposed to be doing and what is expected of them.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Medical Records Documentation', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Medical Records Documentation ', 'Subject:Encourage the Interdisciplinary Treatment Team (IDT) to work as a team and view the Care Plan as a resident-centered collaborative effort to enhance the care and quality of resident life.', 'Description: Interdisciplinary Care Planning requires members of the Interdisciplinary Treatment Team (IDT) to view the Care Plan as a resident centered collaborative effort - rather than as a staff centered document. Learn how to utilize the Care Plan to truly function as a team - working together to enhance the care and quality of resident life.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Census Challenges', 'Instructor: Keith Savell', 'length: 60', 'Rating: 4.45', 'Topic: Creative Solutions to Drive Census ', 'Subject:Learn to evaluate and modify the environment to support our residents with cognitive impairment as they age in place.', 'Description: Residents with dementia and delirium are constantly assessing the environment, looking for clues to help them understand where they are, who others around them are, what they are supposed to be doing and what is expected of them.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Fall Prevention: Reducing Fall Related Injuries', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Guidelines for Health Care Providers ', 'Subject:Encourage the Interdisciplinary Treatment Team (IDT) to work as a team and view the Care Plan as a resident-centered collaborative effort to enhance the care and quality of resident life.', 'Description: Interdisciplinary Care Planning requires members of the Interdisciplinary Treatment Team (IDT) to view the Care Plan as a resident centered collaborative effort - rather than as a staff centered document. Learn how to utilize the Care Plan to truly function as a team - working together to enhance the care and quality of resident life.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Meaningful Engagement', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Creating The Failure Free Activity Program ', 'Subject:Learn to evaluate and modify the environment to support our residents with cognitive impairment as they age in place.', 'Description: Residents with dementia and delirium are constantly assessing the environment, looking for clues to help them understand where they are, who others around them are, what they are supposed to be doing and what is expected of them.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Dementia and Delirium', 'Instructor: Keith Savell', 'length: 60', 'Rating: 4.69', 'Topic: The Importance of Accurate Diagnosis and Treatment ', 'Subject:Encourage the Interdisciplinary Treatment Team (IDT) to work as a team and view the Care Plan as a resident-centered collaborative effort to enhance the care and quality of resident life.', 'Description: Interdisciplinary Care Planning requires members of the Interdisciplinary Treatment Team (IDT) to view the Care Plan as a resident centered collaborative effort - rather than as a staff centered document. Learn how to utilize the Care Plan to truly function as a team - working together to enhance the care and quality of resident life.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Behavior Management', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Using Root Cause ', 'Subject:Learn to evaluate and modify the environment to support our residents with cognitive impairment as they age in place.', 'Description: Residents with dementia and delirium are constantly assessing the environment, looking for clues to help them understand where they are, who others around them are, what they are supposed to be doing and what is expected of them.')";
db.execSQL(sql);
sql="INSERT INTO courses(title, instructor, length, rating, topic, subject, description) VALUES ('Communication: Powerful Tools For...', 'Instructor: Keith Savell', 'length: 60', 'Rating: 5', 'Topic: Powerful Tools For Communicating With Residents ', 'Subject:Encourage the Interdisciplinary Treatment Team (IDT) to work as a team and view the Care Plan as a resident-centered collaborative effort to enhance the care and quality of resident life.', 'Description: Interdisciplinary Care Planning requires members of the Interdisciplinary Treatment Team (IDT) to view the Care Plan as a resident centered collaborative effort - rather than as a staff centered document. Learn how to utilize the Care Plan to truly function as a team - working together to enhance the care and quality of resident life.')";
db.execSQL(sql);
}
public ArrayList<Courses> getCourses()
{
db = getWritableDatabase();
sql = "SELECT title, instructor, length, rating, topic, subject, description FROM courses";
Cursor cursor = db.rawQuery(sql, null);
ArrayList<Courses> courses = new ArrayList<Courses>();
while (cursor.moveToNext())
{
Courses oCourses=new Courses();
oCourses.title=cursor.getString(0);
oCourses.instructor=cursor.getString(1);
oCourses.length=cursor.getString(2);
oCourses.rating=cursor.getString(3);
oCourses.topic=cursor.getString(4);
oCourses.subject=cursor.getString(5);
oCourses.description=cursor.getString(6);
courses.add(oCourses);
}
db.close();
cursor.close();
return courses;
}}
和我的课程CourseDetails显示所选元素:
public class CourseDetails extends Activity {
protected TextView tTitle;
protected TextView tInstructor;
protected TextView tLength;
protected TextView tRating;
protected TextView tTopic;
protected TextView tSubject;
protected TextView tDescription;
protected int courseId;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.course_details);
courseId = getIntent().getIntExtra("COURSE_ID", 0);
SQLiteDatabase db = **(new DBHelper(this))**.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT emp._id, emp.title, emp.instructor, emp.length, emp.rating, emp.topic, emp.subject, emp.description, mgr.title managerTitle, mgr.instructor managerInstructor FROM courses emp LEFT OUTER JOIN courses mgr ON emp.rating = mgr._id WHERE emp._id = ?",
new String[]{""+courseId});
if (cursor.getCount() == 1)
{
cursor.moveToFirst();
tTitle = (TextView) findViewById(R.id.tTitle);
tTitle.setText(cursor.getString(cursor.getColumnIndex("title")));
tInstructor = (TextView) findViewById(R.id.tInstructor);
tInstructor.setText(cursor.getString(cursor.getColumnIndex("instructor")));
tLength = (TextView) findViewById(R.id.tLength);
tLength.setText(cursor.getString(cursor.getColumnIndex("length")));
tRating = (TextView) findViewById(R.id.tRating);
tRating.setText(cursor.getString(cursor.getColumnIndex("rating")));
tTopic = (TextView) findViewById(R.id.tTopic);
tTopic.setText(cursor.getString(cursor.getColumnIndex("topic")));
tSubject = (TextView) findViewById(R.id.tSubject);
tSubject.setText(cursor.getString(cursor.getColumnIndex("subject")));
tDescription = (TextView) findViewById(R.id.tDescription);
tDescription.setText(cursor.getString(cursor.getColumnIndex("description")));
}
}}
非常感谢您的帮助
答案 0 :(得分:3)
错误消息告诉您确切的错误。您正在调用构造函数:
(new DBHelper(this))
这意味着构造函数签名应如下所示:
public DBHelper(Context context)
但是你唯一定义的构造函数就是这个:
public DBHelper(Context context, String name, CursorFactory factory,
int version)
您需要使用正确的参数调用构造函数,或者使用您想要的任何参数添加新的构造函数。
答案 1 :(得分:1)
你正在创建像这样的DBHelper:
new DBHelper(this)
其中“this”是CourseDetails对象。
但是,您提供的唯一构造函数是
public DBHelper(Context context, String name, CursorFactory factory, int version)