2013-05-26 2 views
0


그래서 안드로이드 4.2에서 작동하지만 이전의 안드로이드 버전에서는 작동하지 않는 코드 조각이 있습니다.
Android :보기 제거시 오류

public void onAnimationEnd(Animation animation) { 
      try { 
       ImageView ivCloudView = lCloudArray.get(iCloudCounter); // get View from ArrayList 
       ((ViewGroup) ivCloudView.getParent()).removeView(ivCloudView); //remove View 
       iCloudCounter++; 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     } 

는 내가 나이가 안드로이드 버전에서 작동하지 않는 이유를 모르겠어요. 제거 코드를 변경하고 다음과 같이 바꿉니다 :

ivCloudView.setImageResource(R.drawable.button); 

작동합니다. 내가 무엇을 잘못 생각하는지 모르겠다.

imageviews (구름)는 동적으로 생성되어 lCloudArray에 저장됩니다. 그러나 이상한 부분은 현장에 구름이 하나 밖에 없으면 문제없이 삭제된다는 것입니다.
여러 개의 구름이있는 경우 오류가 발생하기 시작합니다.

는 XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/mainlayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:orientation="vertical" 
android:background="@drawable/goededoelenquiz" 
tools:context=".MainActivity" > 
<TextView 
    android:id="@+id/tvgametitle" 
    android:gravity="center" 
    android:layout_height="200sp" 
    android:layout_width="fill_parent" 
    android:layout_above="@+id/bStartbutton" 
    android:textColor="@color/white" 
    android:textSize="75sp" 
    android:text="@string/gametitle" /> 
<Button 
    android:id="@+id/bStartbutton" 
    android:layout_width="fill_parent" 
    android:layout_height="100sp" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="75sp" 
    android:background="@drawable/button" 
    android:text="@string/startbutton" /> 
<Button 
    android:id="@+id/bHighscore" 
    android:layout_width="fill_parent" 
    android:layout_height="100sp" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="0sp" 
    android:background="@drawable/button" 
    android:text="@string/highscorebutton" /> 

+0

"작동하지 않는다"는 것은 무엇을 의미합니까? 오류가 무엇입니까? –

+0

아마 stacktrace를 인쇄해야합니다. 당신은 IndexOutOfBOundException을 얻고 있습니까? – Blackbelt

+0

이것은 http://gyazo.com/41baaf7da848e4b175f330271dd3b72c 오류 메시지입니다. 치명적인 예외 : 주 NullpointerException – Dytanoth

답변

0

현재 정보 내 생각 엔이 이미지 뷰 (ivCloudView)는 부모가없는 것입니다. 뷰를 제거하기 전에 ivCloudView.getParent()가 null이 아닌지 확인하십시오.

그래도 해결되지 않으면 레이아웃 XML을 게시 해주세요.