2012-05-04 5 views
-2
TextView t =(TextView)findViewById(R.id.place); 
t.setText("A"); 

나는 onCreate() 메서드 내에서 위 코드를 호출합니다. 내 활동은 ListActivity입니다. 그러나 왜 내가 Null 포인터 예외 값을 TextView로 설정하는 중

<TextView android:id="@+id/place" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:textSize="16sp" 
      android:textStyle="bold" 
      android:focusable="false" 
      android:text="" 
      android:layout_gravity="left"/> 

및 해결 방법을하는 텍스트 뷰

정의 된 XML이 나를 여기에 다음과 같은 오류

05-04 14:21:40.840: E/AndroidRuntime(16168): Caused by: java.lang.NullPointerException 

제공하고?

+0

더 많은 코드를 게시하십시오. –

+0

findViewById()는 발견 된 경우 뷰를 반환하고 그렇지 않으면 null을 반환합니다. – yorkw

+0

@ dinesh707 ur는 onCreate 메소드 코드를 게시 할 수 있습니다. – AndroidDev

답변

2
public class yourclass extends Activity{ 
    TextView t; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.patient); 
      t =(TextView)findViewById(R.id.place); 
      t.setText("A"); 
    } 
} 
0

안녕하십니까. 목록보기에 적절한 레이아웃을 설정하지 않은 것으로 보입니다. 달라야

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/gradient_unselected" 
android:orientation="vertical" > 
<ListView 
    android:id="@+id/blacklist_view" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:divider="@drawable/seperator" 
    android:dividerHeight="1dp" > 
</ListView> 

</LinearLayout> 

및 로우 상품 레이아웃 다음의 ListActivity하지 OnCreate

다소 이런 것 레이아웃 설정.