I want to add edit text above the mapview in android
so I created this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/base">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/zoomtext"
>
</EditText>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="myAPIkey"
android:layout_below="@+id/zoomtext"/>
</RelativeLayout>
here’s my java code
package zoom.map;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.widget.EditText;
public class ZoomapActivity extends MapActivity {
EditText zoombtn;
int angkazoom;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
zoombtn = (EditText) findViewById(R.id.zoomtext);
angkazoom = mapView.getZoomLevel();
zoombtn.setText(angkazoom);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
and this is my error log cat
04-18 13:08:37.230: E/AndroidRuntime(309): FATAL EXCEPTION: main
04-18 13:08:37.230: E/AndroidRuntime(309): java.lang.RuntimeException: Unable to start activity ComponentInfo{zoom.map/zoom.map.ZoomapActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x3
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.os.Looper.loop(Looper.java:123)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 13:08:37.230: E/AndroidRuntime(309): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 13:08:37.230: E/AndroidRuntime(309): at java.lang.reflect.Method.invoke(Method.java:521)
04-18 13:08:37.230: E/AndroidRuntime(309): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-18 13:08:37.230: E/AndroidRuntime(309): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-18 13:08:37.230: E/AndroidRuntime(309): at dalvik.system.NativeStart.main(Native Method)
04-18 13:08:37.230: E/AndroidRuntime(309): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x3
04-18 13:08:37.230: E/AndroidRuntime(309): at android.content.res.Resources.getText(Resources.java:201)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.widget.TextView.setText(TextView.java:2817)
04-18 13:08:37.230: E/AndroidRuntime(309): at zoom.map.ZoomapActivity.onCreate(ZoomapActivity.java:21)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 13:08:37.230: E/AndroidRuntime(309): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-18 13:08:37.230: E/AndroidRuntime(309): ... 11 more
I can’t figure out what’s wrong..
No problem with the layout and I have no error in the java
I’ve searched through stackoverflow and haven’t found the answer yet..
This line
Is retrieving an integer value.
When calling
android assumes you are trying to set your text to a String resource ID (an int).. This ID “should” map to a string value.. When it searches for that ID it fails since it doesn’t exist and causes your crash.
If what you want to show is just the zoom level use
to allow your text to show the zoom level in string representation