2012-03-19 6 views
0

私は自分のクラスのアクティビティをextedningしていた間に、自分のプログラムの一部分だけSQLite thathで動作するように私の最初のプログラを作っています。ListActivityを持つデータベース

public class Obvestila extends ListActivity 

私はActivityの代わりにListActivityを拡張する必要がありました。しかし、今、私はこの新しいフォームを開くためにメニューのアイコンをクリックするとクラッシュします。 logcatでは、詳細なエラーは表示されません。

package com.test.testt; 

import java.util.List; 
import java.util.Random; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ArrayAdapter; 

public class Obvestila extends ListActivity{ 
    private CommentsDataSource datasource; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     datasource = new CommentsDataSource(this); 
     datasource.open(); 

     List<Comment> values = datasource.getAllComments(); 

     ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this, 
       android.R.layout.simple_list_item_1, values); 
     setListAdapter(adapter); 
    } 


    public void onClick(View view) { 
     @SuppressWarnings("unchecked") 
     ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter(); 
     Comment comment = null; 
     switch (view.getId()) { 
     case R.id.add: 
      String[] comments = new String[] { "Cool", "Very nice", "Hate it" }; 
      int nextInt = new Random().nextInt(3);   
      comment = datasource.createComment(comments[nextInt]); 
      adapter.add(comment); 
      break; 
     case R.id.delete: 
      if (getListAdapter().getCount() > 0) { 
       comment = (Comment) getListAdapter().getItem(0); 
       datasource.deleteComment(comment); 
       adapter.remove(comment); 
      } 
      break; 
     } 
     adapter.notifyDataSetChanged(); 
    } 

    @Override 
    protected void onResume() { 
     datasource.open(); 
     super.onResume(); 
    } 

    @Override 
    protected void onPause() { 
     datasource.close(); 
     super.onPause(); 
    } 

} 

私は間違っていると思いますか?

+0

にこれを追加,,,,将来的に忘れてはいけません。 .. –

答えて

1

何かエラーがある場合は、必ずここに完全なlogcatを入れて、あなたのmain.xml

<ListView android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/> 
+0

ああ私の神:DIはfalse xmlをロードしていた^^。ありがとう! – HyperX

0

XMLファイルには、android.R.id.list要素はありません。あなたのListViewは、XMLで以下のIDを持っている必要があります。

@android:id/list 
関連する問題