MapActivity在运行程序时崩溃

时间:2012-02-14 11:36:47

标签: android android-mapview mapactivity

我正在尝试使用菜单中的三个选项制作应用程序。

其中一个是谷歌地图视图 当我点击菜单的Map选项时,应用程序将崩溃。

import android.app.Activity;
import android.content.Context;
import android.content.Intent; 
import android.content.res.TypedArray;
import android.os.Bundle; 
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import com.google.android.maps.MapActivity;
import android.widget.AdapterView.OnItemClickListener;

public class GalleryView extends Activity {
    Integer[] pics = {
        R.drawable.leiden1,
        R.drawable.leiden2,
        R.drawable.leiden3,
        R.drawable.leiden4,
        R.drawable.leiden5,
        R.drawable.leiden6,
        R.drawable.leiden7,
        R.drawable.leiden8,
        R.drawable.leiden9,
        R.drawable.leiden10,

    };

    ImageView imageView;

    private static final int MENU1 = Menu.FIRST;
    private static final int MENU2 = Menu.FIRST + 1;
    private static final int MENU3 = Menu.FIRST + 2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        Gallery ga = (Gallery)findViewById(R.id.Gallery01);
        ga.setAdapter(new ImageAdapter(this));

        imageView = (ImageView)findViewById(R.id.ImageView01);
        ga.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {

                imageView.setImageResource(pics[arg2]);

            }

        });

    }


    public class ImageAdapter extends BaseAdapter {

        private Context ctx;
        int imageBackground;

        public ImageAdapter(Context c) {
            ctx = c;
            TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            imageBackground =  ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
            ta.recycle();
        }

        @Override
        public int getCount() {

            return pics.length;
        }

        @Override
        public Object getItem(int arg0) {

            return arg0;
        }

        @Override
        public long getItemId(int arg0) {

            return arg0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150,120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }

    }

    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, MENU1, 0, "Foto's");
        menu.add(0, MENU2, 0, "Teampagina");
        menu.add(0, MENU3, 0, "Route");
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case MENU1:
                Intent myIntent = new Intent(getBaseContext(), GalleryView.class);
                startActivityForResult(myIntent, 0);
                return true;
            case MENU2:
                Intent myIntent2 = new Intent(getBaseContext(), HelloSpinnerActivity.class);
                startActivityForResult(myIntent2, 0);
                return true;
            case MENU3:
                Intent myIntent3 = new Intent(getBaseContext(),  HelloGoogleMapsActivity.class);
                startActivityForResult(myIntent3, 0);
                return true;
        }
        return false;
    }
}

HelloGoogleMapsActivity.java

package me.hellospinner.app;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.MapActivity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class HelloGoogleMapsActivity extends MapActivity {

private static final int MENU1 = Menu.FIRST;
private static final int MENU2 = Menu.FIRST + 1;
private static final int MENU3 = Menu.FIRST + 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main3);

    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
    GeoPoint point = new GeoPoint(52184090, 4481470);
    OverlayItem overlayitem = new OverlayItem(point, "Leidsche En Oegstgeester Hockey Club ","Hofbrouckerlaan 51 2341 LL Oegstgeest");

            itemizedoverlay.addOverlay(overlayitem);


    mapOverlays.add(itemizedoverlay);
    }
@Override
protected boolean isRouteDisplayed() {
    return false;
}
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU1, 0, "Foto's");
    menu.add(0, MENU2, 0, "Teampagina");
    menu.add(0, MENU3, 0, "Route");
    return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU1:
        Intent myIntent = new Intent(getBaseContext(), GalleryView.class);
        startActivityForResult(myIntent, 0);
    return true;
    case MENU2:
    Intent myIntent2 = new Intent(getBaseContext(), HelloSpinnerActivity.class);
    startActivityForResult(myIntent2, 0);
    return true;
    case MENU3:
      Intent myIntent3 = new Intent(getBaseContext(), HelloGoogleMapsActivity.class);
     startActivityForResult(myIntent3, 0);



        return true;

}
    return false;
}
}

logcat的

02-14 19:25:20.866: E/AndroidRuntime(234): Uncaught handler: thread main exiting due to uncaught exception
02-14 19:25:20.885: E/AndroidRuntime(234): android.content.ActivityNotFoundException: Unable to find explicit activity class {me.hellospinner.app/me.hellospinner.app.HelloGoogleMapsActivity}; have you declared this activity in your AndroidManifest.xml?
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.app.Activity.startActivityForResult(Activity.java:2749)
02-14 19:25:20.885: E/AndroidRuntime(234):  at me.hellospinner.app.HelloSpinnerActivity.onOptionsItemSelected(HelloSpinnerActivity.java:73)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.app.Activity.onMenuItemSelected(Activity.java:2170)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:525)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.view.View.onTouchEvent(View.java:4179)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.widget.TextView.onTouchEvent(TextView.java:6540)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.view.View.dispatchTouchEvent(View.java:3709)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.os.Looper.loop(Looper.java:123)
02-14 19:25:20.885: E/AndroidRuntime(234):  at android.app.ActivityThread.main(ActivityThread.java:4363)
02-14 19:25:20.885: E/AndroidRuntime(234):  at java.lang.reflect.Method.invokeNative(Native Method)
02-14 19:25:20.885: E/AndroidRuntime(234):  at java.lang.reflect.Method.invoke(Method.java:521)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-14 19:25:20.885: E/AndroidRuntime(234):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-14 19:25:20.885: E/AndroidRuntime(234):  at dalvik.system.NativeStart.main(Native Method)
02-14 19:25:20.905: I/dalvikvm(234): threadid=7: reacting to signal 3
02-14 19:25:20.905: E/dalvikvm(234): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
02-14 19:25:22.839: I/Process(234): Sending signal. PID: 234 SIG: 9

我希望有人可以帮助我

1 个答案:

答案 0 :(得分:0)

答案在错误日志中我猜,“你在AndroidManifest.xml中声明了这个活动吗?”