2016-10-30 5 views
0

私はこの2番目のアクティビティの作成チュートリアルを行っていますpage 私はすべてを慎重に行っており、エラーが発生しています。なぜ私はコピー/貼り付けを指示するコードをコピー/ペーストするだけなのか、なぜエラーがあるのか​​分かりません!ViewGroupへの予期せぬキャスト:レイアウトタグはRelativeLayoutでした

次のコード行:

ViewGroup layout = (VeiwGroup) findViewById(R.id.activity_display_message); 

は私に、このエラーを与える:

unexpected cast to ViewGroup: layout tag was RelativeLayout.

まあ、私はそれが話しているかわかりません。私はxmlファイルが相対的なレイアウトであることを知っています。しかし、なぜそれが問題なのか、問題が本当にどこにあるのか分かりません。

+1

また、関連コードを掲載する必要があります。 'activity_display_message'はrelativelayout!のIDです。 – Raghunandan

+1

あなたのXMLを見る必要があります。私はそれが何を求めているかを理解するためのチュートリアルに従った。再生できません –

答えて

0

変更ごViewGroupあなたはのViewGroupが親クラスであり、相対的なレイアウトは、ここではいくつかの他のクラスと、それだけの高度なバージョンをあるとしてあなたはRelativeLayout方法の方法の一部が欠けているのViewGroupクラスを呼び出すとき

RelativeLayoutへあなたがのために必要な方法のいくつかを呼び出していないことを見ることができますクラス

@RemoteView 
public class RelativeLayout extends ViewGroup { 
public static final int ABOVE = 2; 
public static final int ALIGN_BASELINE = 4; 
public static final int ALIGN_BOTTOM = 8; 
public static final int ALIGN_END = 19; 
public static final int ALIGN_LEFT = 5; 
public static final int ALIGN_PARENT_BOTTOM = 12; 
public static final int ALIGN_PARENT_END = 21; 
public static final int ALIGN_PARENT_LEFT = 9; 
public static final int ALIGN_PARENT_RIGHT = 11; 
public static final int ALIGN_PARENT_START = 20; 
public static final int ALIGN_PARENT_TOP = 10; 
public static final int ALIGN_RIGHT = 7; 
public static final int ALIGN_START = 18; 
public static final int ALIGN_TOP = 6; 
public static final int BELOW = 3; 
public static final int CENTER_HORIZONTAL = 14; 
public static final int CENTER_IN_PARENT = 13; 
public static final int CENTER_VERTICAL = 15; 
public static final int END_OF = 17; 
public static final int LEFT_OF = 0; 
public static final int RIGHT_OF = 1; 
public static final int START_OF = 16; 
public static final int TRUE = -1; 

public RelativeLayout(Context context) { 
    super((Context)null, (AttributeSet)null, 0, 0); 
    throw new RuntimeException("Stub!"); 
} 

public RelativeLayout(Context context, AttributeSet attrs) { 
    super((Context)null, (AttributeSet)null, 0, 0); 
    throw new RuntimeException("Stub!"); 
} 

public RelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super((Context)null, (AttributeSet)null, 0, 0); 
    throw new RuntimeException("Stub!"); 
} 

public RelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super((Context)null, (AttributeSet)null, 0, 0); 
    throw new RuntimeException("Stub!"); 
} 

public boolean shouldDelayChildPressedState() { 
    throw new RuntimeException("Stub!"); 
} 

public void setIgnoreGravity(int viewId) { 
    throw new RuntimeException("Stub!"); 
} 

public int getGravity() { 
    throw new RuntimeException("Stub!"); 
} 

public void setGravity(int gravity) { 
    throw new RuntimeException("Stub!"); 
} 

public void setHorizontalGravity(int horizontalGravity) { 
    throw new RuntimeException("Stub!"); 
} 

public void setVerticalGravity(int verticalGravity) { 
    throw new RuntimeException("Stub!"); 
} 

public int getBaseline() { 
    throw new RuntimeException("Stub!"); 
} 

public void requestLayout() { 
    throw new RuntimeException("Stub!"); 
} 

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    throw new RuntimeException("Stub!"); 
} 

protected void onLayout(boolean changed, int l, int t, int r, int b) { 
    throw new RuntimeException("Stub!"); 
} 

public RelativeLayout.LayoutParams generateLayoutParams(AttributeSet attrs) { 
    throw new RuntimeException("Stub!"); 
} 

protected android.view.ViewGroup.LayoutParams generateDefaultLayoutParams() { 
    throw new RuntimeException("Stub!"); 
} 

protected boolean checkLayoutParams(android.view.ViewGroup.LayoutParams p) { 
    throw new RuntimeException("Stub!"); 
} 

protected android.view.ViewGroup.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams lp) { 
    throw new RuntimeException("Stub!"); 
} 

public CharSequence getAccessibilityClassName() { 
    throw new RuntimeException("Stub!"); 
} 

public static class LayoutParams extends MarginLayoutParams { 
    @ExportedProperty(
     category = "layout" 
    ) 
    public boolean alignWithParent; 

    public LayoutParams(Context c, AttributeSet attrs) { 
     super((android.view.ViewGroup.LayoutParams)null); 
     throw new RuntimeException("Stub!"); 
    } 

    public LayoutParams(int w, int h) { 
     super((android.view.ViewGroup.LayoutParams)null); 
     throw new RuntimeException("Stub!"); 
    } 

    public LayoutParams(android.view.ViewGroup.LayoutParams source) { 
     super((android.view.ViewGroup.LayoutParams)null); 
     throw new RuntimeException("Stub!"); 
    } 

    public LayoutParams(MarginLayoutParams source) { 
     super((android.view.ViewGroup.LayoutParams)null); 
     throw new RuntimeException("Stub!"); 
    } 

    public LayoutParams(RelativeLayout.LayoutParams source) { 
     super((android.view.ViewGroup.LayoutParams)null); 
     throw new RuntimeException("Stub!"); 
    } 

    public String debug(String output) { 
     throw new RuntimeException("Stub!"); 
    } 

    public void addRule(int verb) { 
     throw new RuntimeException("Stub!"); 
    } 

    public void addRule(int verb, int subject) { 
     throw new RuntimeException("Stub!"); 
    } 

    public void removeRule(int verb) { 
     throw new RuntimeException("Stub!"); 
    } 

    public int getRule(int verb) { 
     throw new RuntimeException("Stub!"); 
    } 

    public int[] getRules() { 
     throw new RuntimeException("Stub!"); 
    } 

    public void resolveLayoutDirection(int layoutDirection) { 
     throw new RuntimeException("Stub!"); 
    } 
} 
} 

ViewGroup class

両者の差がありますrelativelayout.Thatsあなたがエラーをgettinngている理由。

記事で
+0

@Monkey更新の回答を参照 –

-1

(あなたが与えられたリンク)を使用すると、ノートを見つけることができます:

Note: The XML layout generated by previous versions of Android Studio might not include the android:id attribute. The call findViewById() will fail if the layout does not have the android:id attribute. If this is the case, open activity_display_message.xml and add the attribute android:id="@+id/activity_display_message" to the layout element.

が欠落している属性を追加し、エラーがなくなってしなければなりません。

+0

正しいかもしれませんが、これが真であれば、 'layout'をnullに割り当てます。 –

関連する問題