2012-02-25 13 views
0

取得中には、ここでこれは、異なるレベルが追加される予定されているmain3を膨張さSecondActivity Main2.layoutである私のXMLコードヌル例外エラーのLinearLayout

<?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:orientation="horizontal" > 
    <LinearLayout 
     android:id="@+id/HUD_Display" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:background="@drawable/hud" 
     android:contentDescription="HUDContent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/HUD_Text_Element1" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="175dp" 
      android:textSize="20dp" 
      android:text="Hello World" 
      android:tag="hud" 
      android:textColor="@color/Black" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/HUD_Text_Element2" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="2dp" 
      android:textSize="20dp" 
      android:tag="hud" 
      android:text="Hello World HOW" 
      android:textColor="@color/Black" 
      android:typeface="serif" /> 

     <TextView 
      android:id="@+id/HUD_Text_Element3" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="1dp" 
      android:textSize="20dp" 
      android:tag="hud" 
      android:text="Hello World HOW" 
      android:textColor="@color/Black" 
      android:typeface="serif" /> 

      <TextView 
      android:id="@+id/HUD_Text_Element4" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:layout_marginTop="1dp" 
      android:textSize="20dp" 
      android:text="Hello World" 
      android:textColor="@color/Black" 
      android:typeface="serif" /> 
</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal" > 

      <Button 
       android:id="@+id/Btn01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="15dp" 
       android:layout_marginTop="100dp" 
       android:onClick="handleClick" 
       android:textColor="@color/White" 
       android:textSize="25dp" 
       android:textStyle="bold" 
       android:typeface="normal" /> 

      <Button 
       android:id="@+id/Btn1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="100dp" 
       android:onClick="handleClick" 
       android:textColor="@color/White" 
       android:textSize="25dp" 
       android:textStyle="bold" 
       android:typeface="sans" /> 
     </LinearLayout> 

です。今、私は..Hereは私がHUDdisplayの時点でNULL例外エラーを取得していますサンプルクラス

パブリッククラスサンプル{

Sample(Context context, View vs, ViewGroup layout) { 

LinearLayout HUDDisplay=(LinearLayout) layout.findViewById(R.id.HUD_Display); 

Log.d("Check", "msg" + HUDDisplay.getContentDescription().toString()); 


    int count =HUDDisplay.getChildCount(); 

    Log.d("TextView","Count" + count);  
    for(int i=0;i<count;++i) 
    { 
     Log.d("TextView","textview" + HUDDisplay.getChildAt(i).toString()); 
    } 


} 

ある?Sampleクラスのオブジェクトを作成している

setContentView(R.layout.main2); 

    // ViewGroup where n number of view is going to added 
    ViewGroup layout= (ViewGroup) findViewById(R.id.main3); 

    // inflating the layout depending on the level 
    View view = View.inflate(this,FirstActivity.levels, null); 

    Sample sam= new Sample(view.getContext(), level, layout); 

これは間違っていますか? 私はあなたがこの行に線形レイアウトオブジェクトを得た場合

+0

まだ完了していない場合は、プロジェクトをクリーンにして再構築してください。 – noob

答えて

0

としてtextvalueを設定したいです。

ViewGroup layout= (ViewGroup) findViewById(R.id.main3); 

NULLである可能性があります。

+0

同じヌル例外エラー... – user1201239

0

チェックを何が起こるか見て、見るためにリニアレイアウトを変更してみてください

+0

上記のコードxmlはmain3.xml以外です。訳が分からない? – user1201239