2012-02-20 9 views
0

私は問題を持っているに出メインスレッドエラー:...キャッチされない例外により

02-20 02:57:09.854: E/AndroidRuntime(12431): Uncaught handler: thread main exiting due to uncaught exception" 

...後で...

02-20 02:57:09.864: E/AndroidRuntime(12431): java.lang.ClassCastException: java.util.ArrayList 

。 SQLiteの移入リストビュー..in、ListViewコントロールが正常に動作しますが、後で私が選択したリストビューの項目のパラメータを取得し、他のレイアウトでそれを表示するには、onListItemClickを使用しようとすると、プログラムが停止し、DDMSはこれを言います「捕捉されなかったハンドラ:捕捉されなかった例外によるスレッドのメイン終了」は後で「java.lang.ClassCastExcept ion:java.util.ArrayList "ListViewで"多分私はArraylistの私のアダプタを処理した?データを受信し、ショーのために

public class lay_main extends ListActivity 
    { 
    public ListView list; 
public DBHelper myAdap; 
protected SQLiteDatabase db; 
public Cursor cursor; 
DBHelper Context; 
DBHelper ArrayList; 

//adapter cAdapter class 
protected ListAdapter adapter; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.lay_main); 

    collectXML(); 
    setupDataBase(); 
    setupAdapter(); 

}  
private void collectXML() 
{ 
    list = (ListView)findViewById(android.R.id.list); 

} 

public void setupDataBase() { 
    myAdap = new DBHelper(getApplicationContext()); 
    myAdap.insertCourses();    
} 

public void setupAdapter() 
{ 
if(myAdap.getCourses()!=null) 
    { 
    cAdapter adapter = new cAdapter(this, R.layout.list_courses, myAdap.getCourses()); 
    list.setAdapter(adapter); 
    } 
} 
public void onListItemClick(ListView parent, View view, int position, long id) 
{ 
     super.onListItemClick(parent, view, position, id); 
     Intent intent = new Intent(this, CourseDetails.class); 
     Cursor cursor = (Cursor) myAdap.getItem(position); 
     intent.putExtra("COURSE_ID", cursor.getInt(cursor.getColumnIndex("title"))); 
     startActivity(intent); 
} 
} 

私のクラスのCourseDetails:

これは私のメインクラスです

public class CourseDetails<BDHelper> 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 title, instructor, length, rating, topic, subject, description FROM courses",   
      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"))); 

    } 


}} 

マイアダプタクラス:私はないことを

public class cAdapter extends ArrayAdapter { 
Context context; 
ArrayList<Courses> courses; 

@SuppressWarnings("unchecked") 
public cAdapter(Context context, int layout_id, ArrayList<Courses> Courses) { 

    super(context, layout_id, Courses); 
    this.context=context; 
    this.courses=Courses; 


} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View row = inflater.inflate(R.layout.list_courses, null); 
    try{ 
     //components 
     TextView txt_title=(TextView)row.findViewById(R.id.txt_title); 
     TextView txt_instructor=(TextView)row.findViewById(R.id.txt_instructor); 
     TextView txt_length=(TextView)row.findViewById(R.id.txt_length); 
     TextView txt_rating=(TextView)row.findViewById(R.id.txt_rating); 
     TextView txt_topic=(TextView)row.findViewById(R.id.txt_topic); 

     //asign values 
     txt_title.setText(courses.get(position).title); 
     txt_instructor.setText(courses.get(position).instructor); 
     txt_length.setText(courses.get(position).length); 
     txt_rating.setText(courses.get(position).rating); 
     txt_topic.setText(courses.get(position).topic); 

    }catch(Exception ex){}  
    return row; 
} 
} 

間違って、本当にあなたの助けに感謝します。

+0

あなたを貼り付けgetItemメソッドコード。 – jeet

+0

こんにちはjitendra、読み取りのためのおかげで、私のクラスのCourseDetailsは、受信およびクラスlay_mainからのデータを示しています。 – JLouis

答えて

1

アダプタのオーバーライドのgetItem方法とのgetItem、

Override 
public Courses getItem(int position) 
{ 
    return courses.get(positon); 
} 

とSetupAdapter方法でからCourcesオブジェクトを返します。

public void setupAdapter() 
{ 
if(myAdap.getCourses()!=null) 
    { 
    adapter = new cAdapter(this, R.layout.list_courses, myAdap.getCourses()); 
    list.setAdapter(adapter); 
    } 
} 

と、次のようによってitemClickに変更します。

public void onListItemClick(ListView parent, View view, int position, long id) 
{ 
     super.onListItemClick(parent, view, position, id); 
     Intent intent = new Intent(this, CourseDetails.class); 
     Courses course= (Courses) adapter.getItem(position); 
     intent.putExtra("COURSE_ID", course.title)); 
     startActivity(intent); 
} 
+0

どうもありがとうJitendra、これは私にエラーを送信します。なぜ、コースへのArrayList からキャストできませんか? – JLouis

+0

編集した答え – jeet

+0

のgetItemメソッドをオーバーライドしているがしかし、私は、後でCourseDetails.classで別の問題を過ごす、それは明らかに解決することを、どうもありがとうございました「キャッチされないハンドラ:キャッチされない例外によりに出メインスレッド」今 " java.lang.RuntimeException:android.database.sqlite.SQLiteException:範囲外のバインドまたは列のインデックス:{activityComponentInfo com.mariposatraining.courses/com.mariposatraining.courses.CourseDetails開始}にできません0x2b6be8を扱う「が、私は、私がすべきだと思いますその詳細を解決する別の質問を開いて、明らかにそのクラス内のカーソルで検索を実行するSQLiteのステートメントを間違っているよ! – jeet

関連する問題