2012-02-13 4 views
0

기본적으로 listview (QSLite로 생성)의 결과를 표시하려고하지만 CourseDetails 클래스의 결과로 listview 요소를 추출하면이 문제가 발생합니다.Android-SQLite : DBHelper 생성자가 정의되지 않았습니다.

, 나는 이것에 대한 DBHelper 클래스를 사용하고

"설명 리소스 경로 위치 유형 생성자가 DBHelper (CourseDetails가) 정의되지 않은 CourseDetails.java/MariposaTrainingMobile/SRC/COM/mariposatraining/코스 (31) 자바 문제를 줄입니다"하지만, 왜 프로그램이 저에게 오류를 보내고, 문제에 대한 해결책을 제시하지 않는지 모르겠다. 내 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"))); 

    } 

}} 

정말 당신의 도움

답변

3

오류 메시지가 잘못을 정확히 알려줍니다 감사하겠습니다. 생성자의 서명은 다음과 같이해야 의미

(new DBHelper(this)) 

: 당신은 생성자를 호출하고

public DBHelper(Context context) 

그러나 당신이 정의한 유일한 생성자이 하나입니다

public DBHelper(Context context, String name, CursorFactory factory, 
    int version) 

올바른 인수를 사용하여 생성자를 호출하거나 원하는 인수가있는 새 생성자를 추가해야합니다.

+0

나에게 말할 수있다? 대단히 감사합니다! – JLouis

+0

누락 된 매개 변수를 모두 제공해야합니다. 매개 변수의 의미에 대한 설명서를 참조하십시오. http://goo.gl/1eGr4 –

1

이 같은 DBHelper 만드는 :

은 "이"입니다
new DBHelper(this) 

CourseDetails 오브젝트.

그러나, 사용자가 제공하는 유일한 생성자는 내가 제대로 재현하지 않고 생성자를 호출하는 방법을

public DBHelper(Context context, String name, CursorFactory factory, int version) 
+0

하지만 실제로 DHBHelper를 새로 작성하지 않고 작성한 빌더를 올바르게 정의하는 방법을 모르므로 도움을 많이 주셔서 감사합니다. – JLouis

관련 문제