Issue
I'm discover android programming and I'm facing following error : textview cannot be cast to org.mapsforge.android.maps.MapView.
the following command is generating this error :
this.vuemap = (MapView) findViewById(R.id.vuemap);
My mainscreen.xml is as follow :
<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>`
What is quite strange is that if I invert textview/mapview position in the layout, there is no more problem.
<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>`
Solution
Cleaning the project ("Project -> Clean") may solve casting errors for modified the xml layout file. I think this action may also solve the problem if the text appear in another textview than the one it was supposed to appear. Thanks to Greg!
Answered By - Got
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.