2

Androidのマップビューの上に編集テキストを追加したいので、このレイアウトを作成しました

<?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>

これが私のJavaコードです

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;
}
}

これは私のエラーログ猫です

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

何が問題なのかわかりません。レイアウトに問題はなく、stackoverflowで検索したJavaにエラーはありませんが、まだ答えが見つかりません。

4

1 に答える 1

2

この行

angkazoom = mapView.getZoomLevel();

整数値を取得しています。

電話するとき

zoombtn.setText(angkazoom);

androidは、テキストを文字列リソースID(int)に設定しようとしていると想定します。このIDは文字列値に「マップする必要があります」。そのIDを検索すると、存在しないため失敗し、クラッシュが発生します。 。

表示したいのがズームレベルだけの場合は、

zoombtn.setText(angkazoom + "");

テキストに文字列表現でズームレベルを表示できるようにします

于 2012-04-18T19:20:51.443 に答える