2011-01-04 2 views
0

내 응용 프로그램이 에뮬레이터에서 시작할 때마다 응용 프로그램이 충돌합니다. 여기java.lang.UnsupportedOperationException으로 인해 시작시 응용 프로그램이 충돌 함 : AdapterView에서 addView (View, LayoutParams)가 지원되지 않습니다.

01-02 17:20:58.859: ERROR/AndroidRuntime(249): Uncaught handler: thread main exiting due to uncaught exception 

01-02 17:20:58.889: ERROR/AndroidRuntime(249): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shoppinglist/com.shoppinglist.ShoppingList}: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.app.ActivityThread.access$2100(ActivityThread.java:116) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.os.Handler.dispatchMessage(Handler.java:99) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.os.Looper.loop(Looper.java:123) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at android.app.ActivityThread.main(ActivityThread.java:4203) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at java.lang.reflect.Method.invokeNative(Native Method) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at java.lang.reflect.Method.invoke(Method.java:521) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 

01-02 17:20:58.889: ERROR/AndroidRuntime(249):  at dalvik.system.NativeStart.main(Native Method)** 

내 된 .java 파일입니다 :

package com.shoppinglist; 

import android.app.ListActivity; 
import android.app.Dialog; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class ShoppingList extends ListActivity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button button1main = (Button) findViewById(R.id.Button01main); 
    button1main.setOnClickListener(new OnClickListener() { 
    @Override 
     public void onClick(View v) { 
     final Dialog dialog = new Dialog(ShoppingList.this); 
     dialog.setContentView(R.layout.maindialog); 
     dialog.setCancelable(true); 
     Button button = (Button) dialog.findViewById(R.id.cancel); 
     button.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      dialog.dismiss(); 
     } 
     }); 
     dialog.show(); 
     } 
    }); 
    } 
} 

내 layout.xml :

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFCC00" 
    android:padding="10dp" 
    android:id="@+id/listview"> 
     <Button 
      android:id="@+id/Button01main" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
    android:text="Add item..."/> 
</ListView> 

내 대화 XML :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/layout_root" 
    android:orientation="vertical" 
    android:background="#FFFFFF" 
    android:minHeight="100dp" 
    android:minWidth="300dp"> 
    <EditText 
    android:id="@+id/edittext" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="Type the name of an item here..."> 
    </EditText> 
<LinearLayout 
    android:id="@+id/button_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_gravity="right"> 
    <Button 
    android:id="@+id/ok" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="OK" 
    android:layout_gravity="bottom"> 
    </Button> 
    <Button 
    android:id="@+id/cancel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Cancel" 
    android:layout_gravity="bottom"> 
    </Button> 
    </LinearLayout> 
</LinearLayout> 

여기에 로그 캣입니다 어떤 도움을 주시면 감사하겠습니다. 수정을위한 코드 샘플이 필요합니다. 경험이별로 없습니다.

답변

3

레이아웃 xml에서 ListView 내에 버튼을 추가하려고합니다. ListView는 AdapterView로, 오류가 표시되어 있으므로 비슷한 '물건'목록을 제공하는 어댑터로 채워야합니다. 배열 목록의 문자열 목록이나 사용자 정의보기 목록이 될 수 있습니다. 생성하지만 모두 기본적으로 동일한 유형입니다. 예를 들어 버튼을 추가 할 수 없으면 다른 하나에 문자열을 추가하십시오. ListView에서 원하는 것을 제공하는 어댑터를 만듭니다.

+0

코드 예제가 필요합니다. 경험이 없습니다. – Cg2916

+0

신경 쓰지 마라. LinearLayout에이 모든 것을 포함하기로 결정했다. – Cg2916

+0

안드로이드의 ListView 구현은 어리석게도 모호한 체조를 필요로하는 것처럼 보인다. 제가 생각하기에 아마도 여러분 중 대부분에게는 분명 할 것입니다. 그러나 왜 지금 2 일 동안이 같은 오류가 발생하는지 알아 내려고 노력해 왔기 때문에 지나치게 복잡하다고 생각합니다. –

관련 문제