0

I need to search on name of teacher and display all information about it when user enter teacher name

I have wirrten this code but its given me run time error this error is: FATAL EXCEPTION: main

this is GetRecord method

 public Cursor getRecord(String n1) throws SQLException 
 {
      Cursor mCursor =db.query(true, databaseName, new String[] {facultyc,
                 deparmentc, namec, officeNumberc,Phonec ,emailAddressc,officeHourc},namec + "=" + n1, null, null, null, null, null);
      if (mCursor != null) {
           mCursor.moveToFirst();
      }
      return mCursor;
 }

and this search method, its perfom when user click on search button

public void search(){

    db.open();
    Cursor c = db.getRecord(n);
    if (c.moveToFirst()){
        t1.setText(c.getString(0));
        t2.setText(c.getString(1));
        t3.setText(c.getString(2));
        t4.setText(c.getString(3));
        t5.setText(c.getString(4));
        t6.setText(c.getString(5));
        t7.setText(c.getString(6));

    }

    else
        Toast.makeText(this, "this Dr not found", Toast.LENGTH_LONG).show();
    db.close();
}

this error appear

05-04 13:39:52.856: E/Trace(4001): error opening trace file: No such file or directory (2)

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • post your stacktrace. – AnujMathur_07 May 04 '13 at 11:56
  • Can you post your logcat? – Dave May 04 '13 at 11:56
  • 05-04 11:30:58.736: E/AndroidRuntime(1135): FATAL EXCEPTION: main 05-04 11:30:58.736: E/AndroidRuntime(1135): – user2324084 May 04 '13 at 11:59
  • @user2324084: this is the only error line you are getting?? – AnujMathur_07 May 04 '13 at 12:01
  • Please provide complete **stacktrace related to the issue** . Follow the [link for your ref](http://stackoverflow.com/a/11608775/2345913) – CRUSADER May 04 '13 at 12:02
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.Information}: android.database.sqlite.SQLiteException: no such table: teachers (code 1): , while compiling: SELECT DISTINCT faculty, deparment, name, officeNumber, phoneNumber, emailAddress, officeHour FROM teachers WHERE name=aaa 2230) – user2324084 May 04 '13 at 12:03
  • 1
    The table with name **teachers** is yet not created. First create the table with that name by using Create Or replace query and then go with your retrieving code – CRUSADER May 04 '13 at 12:06
  • DBAdapter db = new DBAdapter(this); i use this to create table – user2324084 May 04 '13 at 12:11

0 Answers0