私は私のAndroidコードにいくつかの問題があります
これが私のMainActivity.javaです
public class MainActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
Button b;
EditText e;
TextView t;
String x;
String longi ;
String lati ;
Spinner naja;
String[] jalan = {"A.Yani","Ambengan", "Anjasmoro","Baliwerti","Basuki Rahmat","Bintoro","Ciliwung","Darmo Raya","Darmokali","Diponegoro Raya","Dharmawangsa","Dinoyo","Embong Kemiri","Embong Malang"};
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.bawah);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
MapController mc = mapView.getController();
switch (keyCode)
{
case KeyEvent.KEYCODE_3:
mc.zoomIn();
break;
case KeyEvent.KEYCODE_1:
mc.zoomOut();
break;
}
return super.onKeyDown(keyCode, event);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
naja=(Spinner)findViewById(R.id.simpleGM_adress);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, jalan);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
naja.setAdapter(aa);
t=(TextView)findViewById(R.id.simpleGM_tv);
e=(EditText)findViewById(R.id.simpleGM_adress);
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
/*
mc = mapView.getController();
String coordinates[] = {longi, lati};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();*/
}
public void clickHandler(View view){
switch (view.getId()){
case R.id.simpleGM_btn_search:
x = jalan[naja.getSelectedItemPosition()];
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nama_jalan", x));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.1.4/android/kordinat.php", postParameters);
String result = response.toString();
//parse json data
try{
longi = "";
lati = "";
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","nama_jalan: "+json_data.getString("nama_jalan")+
", latitude: "+json_data.getString("latitude")+
", longitude: "+json_data.getString("longitude")
);
if(result.equals(null)){
//Get an output to the screen
longi += "Data tidak ada";
}
else{
lati += json_data.getString("latitude");
longi += json_data.getString("longitude");
}
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
try{
mc = mapView.getController();
String coordinates[] = {longi, lati};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
mc.animateTo(p);
mc.setZoom(17);
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapView.invalidate();
}
catch(Exception e){
Log.e("log_tag","Error in Display!" + e.toString());;
}
}
catch (Exception e) {
Log.e("log_tag","Error in http connection!!" + e.toString());
}
break;
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
これが私のmain.xmlです
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/simpleGM_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/simpleGM_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tentukan Jalanmu"
android:layout_x="11px"
android:layout_y="5px"
>
</TextView>
<Spinner
android:id="@+id/simpleGM_adress"
android:layout_width="240px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="12px"
android:layout_y="30px"
></Spinner>
<Button
android:id="@+id/simpleGM_btn_search"
android:layout_width="59px"
android:layout_height="wrap_content"
android:layout_x="256px"
android:layout_y="30px"
android:text="find"
android:onClick="clickHandler"
>
</Button>
<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:layout_x="2px"
android:layout_y="100px"
android:clickable="true"
android:apiKey="00j2bA4ivSvH0cSDJJ4aiPiVCq_OSH0adwf6I2w"
/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</AbsoluteLayout>
これが私のAndroidManifest.xmlです
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="udin.googlemaps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
プログラムを実行すると、次のようなエラーが表示されます
"java.lang.RuntimeException:アクティビティを開始できません
ComponentInfo {udin.googlemaps / udin.googlemaps.MainActivity}:java.lang.ClassCastException:android.widget.Spinner"
誰かがこのエラーを解決するのを手伝ってもらえますか?
なぜこれが起こっているのですか?
どんな助けでも大いに感謝します。
ありがとうございました。