0

Android プログラミングを発見しましたが、次のエラーに直面しています: textview は org.mapsforge.android.maps.MapView にキャストできません。

次のコマンドは、このエラーを生成しています:

this.vuemap = (MapView) findViewById(R.id.vuemap);

私のmainscreen.xmlは次のとおりです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainView"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
        android:id="@+id/trtext"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#47FFFFFF"      
        android:gravity="right"
        android:text="0"
        android:textSize="50dp">
    </TextView>
    <TextView
        android:id="@+id/tltext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#47000000" 
        android:text="0"
        android:textSize="50dp" >
    </TextView> 
    <org.mapsforge.android.maps.MapView
    android:id="@+id/vuemap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"   
    android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" >
    </org.mapsforge.android.maps.MapView>


</RelativeLayout>`

非常に奇妙なのは、レイアウトで textview/mapview の位置を反転させても、問題がなくなることです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainView"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
   <org.mapsforge.android.maps.MapView
    android:id="@+id/vuemap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"   
    android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true" >
    </org.mapsforge.android.maps.MapView>

    <TextView
        android:id="@+id/trtext"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#47FFFFFF"      
        android:gravity="right"
        android:text="0"
        android:textSize="50dp">
   </TextView>
   <TextView
        android:id="@+id/tltext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#47000000" 
        android:text="0"
        android:textSize="50dp" >
   </TextView>
</RelativeLayout>`
4

1 に答える 1

0

プロジェクトをクリーンアップする(「プロジェクト->クリーン」)と、変更されたxmlレイアウトファイルのキャストエラーが解決される場合があります。このアクションは、テキストが表示されるはずのテキストビューとは別のテキストビューに表示される場合にも問題を解決できると思います。グレッグに感謝します!

于 2012-10-09T06:12:19.210 に答える