2013-04-12 1 views
0

다음 예외가 발생 함 : [java.lang.UnsupportedOperationException에 의해 발생 함 : addView (View, layoutParams)가 AdapterView에서 지원되지 않습니다. ] 아래의 코드 조각.java.lang.UnsupportedOperationException에 의해 발생 함 : AdapterView에서 addView (View, layoutParams)가 지원되지 않음

public class MedReminderActivity extends ListActivity { 

    private static final String[] MEDS = new String[] { "Dafalgan", "Citrozone" }; 

    private ProgressDialog mProgressDialog = null; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     // setContentView(R.layout.main); 
     Cursor c = null; 
     ListAdapter cursorListAdapter = new SimpleCursorAdapter(this, R.layout.list_item_my_medicines, c, new String[] { "name" }, new int[] { R.id.list_name }); 
     ListAdapter listAdapter = new ArrayAdapter<String>(this, R.layout.list_item_my_medicines, MEDS); 
     setListAdapter(listAdapter); 

     OnClickListener testButton = new OnClickListener() { 
      public void onClick(View v) { 
       Cursor cursor = getContentResolver().query(MedicineContentProvider.CONTENT_URI, new String[] { Reminder.ID, "name", "method" }, "name LIKE ?", new String[] { "%2%" }, null); 

       List<Medicine> medicines = MedicineMapper.mapCursorToMedicines(cursor); 

       cursor = getContentResolver().query(ReminderContentProvider.CONTENT_URI, new String[] { Medicine.ID, "medicine_id", "time" }, null, null, null); 

       List<Reminder> reminders = ReminderMapper.mapCursorToReminders(cursor); 
      } 
     }; 

     Button button = (Button) findViewById(R.id.button1); 
     button.setOnClickListener(testButton); 
     // OnClickListener testButton = new OnClickListener() { 
     // public void onClick(View v) { 
     // Cursor cursor = 
     // getContentResolver().query(MedicineContentProvider.CONTENT_URI, new 
     // String[] { Reminder.ID, "name", "method" }, "name LIKE ?", new 
     // String[] { "%2%" }, null); 
     // 
     // List<Medicine> medicines = 
     // MedicineMapper.mapCursorToMedicines(cursor); 
     // 
     // cursor = 
     // getContentResolver().query(ReminderContentProvider.CONTENT_URI, new 
     // String[] { Medicine.ID, "medicine_id", "time" }, null, null, null); 
     // 
     // List<Reminder> reminders = 
     // ReminderMapper.mapCursorToReminders(cursor); 
     // } 
     // }; 
     // 
     // Button button = (Button) findViewById(R.id.button1); 
     // button.setOnClickListener(testButton); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     MenuInflater menuInflater = getMenuInflater(); 
     menuInflater.inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
     case R.id.alarmMenu: 
      startActivity(new Intent(this, AlertTestLauncher.class)); 
      return true; 
     case R.id.settingsMenu: 
      Intent intent = new Intent(this, EditPreferencesActivity.class); 
      startActivity(intent); 
      return true; 
     case R.id.medsMenu: 
      startActivity(new Intent(this, MedsActivity.class)); 
      return true; 
     case R.id.remindersMenu: 
      startActivity(new Intent(this, RemindersActivity.class)); 
      return true; 
     case R.id.smartMenu: 
      startActivity(new Intent(this, SmartPreferencesActivity.class)); 
      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
     } 
    } 

    public void onProgressUpdate(String... args) { 
     // here you will have to update the progressbar 
     // with something like 
     mProgressDialog.setProgress(Integer.parseInt(args[0])); 
    } 

    @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
     // TODO Auto-generated method stub 
     // Toast.makeText(this, "klik op item " + position, 
     // Toast.LENGTH_LONG).show(); 

     Intent i = new Intent(this, MedDetailActivity.class); 
     i.putExtra("medname", MEDS[position]); 
     startActivity(i); 

     super.onListItemClick(l, v, position, id); 
    } 

} 

java.lang.RuntimeException가 : java.lang.UnsupportedOperationException가 : addView (보기의 LayoutParams 활동 구성 요소 정보를 { be.droid.medminder/be.bedroid.medminder.MedReminderActivity} 시작할 수 없습니다)는 AdapterView에서 지원되지 않습니다.

문제, 도와주세요 위치를 알아낼 수 없습니다! 미리 감사드립니다.

+1

** 전체 ** 스택 추적을 게시하십시오. – BackSlash

답변

2

주요 에러 때문에 어댑터 뷰 AdapterView 아래에있는 텍스트 뷰이었다. 사실 AdapterView 아래에 뷰가 없어야합니다. TextView를 제거하면 문제가 해결됩니다 ..! : D