2

メインの xml レイアウトを微調整し、相対レイアウトでさまざまなビューの位置を調整していましたが、突然エミュレーターで起動すると、次のメッセージでクラッシュしました: ClassCastException

私のXML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >

 <com.example.bingbong.Render
    android:id="@+id/render"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@color/pattern5"
    android:clickable="true" />

<TextView
    android:id="@+id/fps"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="fpasds"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/score_top"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="asd"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/score_bot"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:text="asfa"
    android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

エラーログ:

10-30 20:25:33.266: E/AndroidRuntime(269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bingbong/com.example.bingbong.Main_Activity}: java.lang.ClassCastException: android.widget.TextView
...
10-30 20:25:33.266: E/AndroidRuntime(269): Caused by: java.lang.ClassCastException: android.widget.TextView
10-30 20:25:33.266: E/AndroidRuntime(269):  at com.example.bingbong.Main_Activity.onCreate(Main_Activity.java:26)

Main_Activity - 26 行目は次のとおりです。

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main_layout);
        r = (Render) findViewById(R.id.render);   // <--- Line 26.
        r.setView((TextView)findViewById(R.id.fps),(TextView)findViewById(R.id.score_top),(TextView)findViewById(R.id.score_bot));
    }
4

2 に答える 2

4

ビューを移動したり、ビューのタイプを変更したりしている場合(つまり、TextViewがボタンに変更されている場合など)に、これが発生することがあります。私にとって通常それを修正するのは、クリーンビルドを行うことです。

Eclipseの[プロジェクト]メニューで[クリーン...]を選択し、すべてのプロジェクトを実行するか、その特定のプロジェクトを選択します。

于 2012-10-30T20:38:15.927 に答える
0

プロジェクトをきれいにする必要があります。このエラーが頻繁に発生します

于 2012-10-30T20:54:31.987 に答える