ActivityNotFoundException(MapActivity)

时间:2011-07-02 11:22:25

标签: android dictionary mapactivity

我的应用程序中有一个MapActivity。我把它包含在我的清单文件中,但是当我运行应用程序时,一切都运行正常,除了MapActivity,每当我尝试通过单击一个Button来启动MapActivity时它会产生以下错误,

07-02 18:06:39.752: ERROR/AndroidRuntime(354): FATAL EXCEPTION: main
07-02 18:06:39.752: ERROR/AndroidRuntime(354): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xtreme.iSenegal/java.util.Map}; have you declared this activity in your AndroidManifest.xml?
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:2473)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:277)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at com.xtreme.iSenegal.Activity1.replaceContentView(Activity1.java:28)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at com.xtreme.iSenegal.Details$2.onClick(Details.java:94)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.view.View.performClick(View.java:2408)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.view.View$PerformClick.run(View.java:8816)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.os.Handler.handleCallback(Handler.java:587)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.os.Looper.loop(Looper.java:123)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at java.lang.reflect.Method.invokeNative(Native Method)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at java.lang.reflect.Method.invoke(Method.java:521)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-02 18:06:39.752: ERROR/AndroidRuntime(354):     at dalvik.system.NativeStart.main(Native Method)

我的MapActivity有什么问题?为什么没找到?

我的MapActivity代码:

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

public class Map扩展了MapActivity {

ArrayList<ListCellInfo> mapsearchresults=new ArrayList<ListCellInfo>();

MapView mapView;
List<Overlay> mapOverlays;
MapController myMapController;

MyXMLHandler myXMLHandler = new MyXMLHandler();

public static int flag=0;

@Override
protected boolean isRouteDisplayed() {
    return false;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

    final EditText SearchForMap = (EditText) findViewById(R.id.editTextmap);

    Button bckbtn = (Button) findViewById(R.id.retourmap);
    bckbtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if (Details.back_activity_flag == 1) {

                InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.hideSoftInputFromWindow(SearchForMap.getWindowToken(), 0);
                Intent myIntent = new Intent(v.getContext(), Details.class);
                Activity1.group.replaceContentView("Details", myIntent);

            }
            else if (Details.back_activity_flag == 2) {

                InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.hideSoftInputFromWindow(SearchForMap.getWindowToken(), 0);
                Intent myIntent = new Intent(v.getContext(), Details.class);
                Activity2.group.replaceContentView("Details", myIntent);

            }
            else if (Details.back_activity_flag == 3) {

                InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.hideSoftInputFromWindow(SearchForMap.getWindowToken(), 0);
                Intent myIntent = new Intent(v.getContext(), Details.class);
                Activity3.group.replaceContentView("Details", myIntent);

            }

        }
    });

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

    mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.black_pin_img);
    MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable,this);

    /*Log.v("Details Lattitude",(int)(Details.lattitude* 1e6)+"");
    Log.v("Details Longitude",(int)(Details.longitude* 1e6)+"");*/

    GeoPoint point = new GeoPoint((int)(Details.lattitude* 1e6),(int)(Details.longitude* 1e6));

    mapView.setFocusable(true);
    myMapController = mapView.getController();
    myMapController.animateTo(point);
    myMapController.setZoom(18);
    myMapController.setCenter(point);

    OverlayItem overlayitem = new OverlayItem(point, Details.name, "");

    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);

    mapView.setStreetView(true);


    RelativeLayout relativelayout = (RelativeLayout) findViewById(R.id.relativeLayoutmap);
    relativelayout.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(SearchForMap.getWindowToken(), 0);

        }
    });

    final MapItemizedOverlay itemizedoverlay1=itemizedoverlay;

    Button searchBtn = (Button) findViewById(R.id.searchbuttonmap);
    searchBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(SearchForMap.getWindowToken(), 0);

            String getSearchText = SearchForMap.getText().toString();

            if(getSearchText.length()!=0){

                String[] fav=getSearchText.split(",");

                try {

                    /** Handling XML */
                    SAXParserFactory spf = SAXParserFactory.newInstance();
                    SAXParser sp = spf.newSAXParser();
                    XMLReader xr = sp.getXMLReader();

                    /** Send URL to parse XML Tags */

                    InputStream inputFile;

                    SharedPreferences flag = getSharedPreferences(iSenegal.Flag, MODE_PRIVATE);
                    String getFlag = flag.getString("Flag", "");

                    if(getFlag.equals("0"))
                        inputFile = getResources().openRawResource(R.raw.alldata);
                    else
                        inputFile = new BufferedInputStream(new FileInputStream("/sdcard/alldata.xml"));

                    xr.setContentHandler(myXMLHandler);
                    xr.parse(new InputSource(inputFile));

                } catch (Exception e) {
                    System.out.println("XML Pasing Excpetion = " + e);

                }

                for(int i=0;i<fav.length;i++){

                    for(int j=0;j<myXMLHandler.results.size();j++){

                        if(myXMLHandler.results.get(j).getSearchTag().toLowerCase().contains(fav[i].toLowerCase()))
                          mapsearchresults.add(myXMLHandler.results.get(j));

                    }
                }
                myXMLHandler.results.clear();

                if(!mapView.getOverlays().isEmpty()) 
                { 
                    mapOverlays.clear();
                    itemizedoverlay1.mOverlays.clear();
                    mapView.invalidate();

                }

                if(mapsearchresults.size()>0){

                    GeoPoint cpoint = new GeoPoint((int)(14.745335 * 1e6),(int)(-17.42157 * 1e6));

                    mapView.setFocusable(true);
                    myMapController = mapView.getController();
                    myMapController.animateTo(cpoint);
                    myMapController.setZoom(7);
                    myMapController.setCenter(cpoint);

                    for(int k=0;k<mapsearchresults.size();k++){

                        GeoPoint point1 = new GeoPoint((int)((mapsearchresults.get(k).getLatitude())* 1e6),(int)((mapsearchresults.get(k).getLongitude())* 1e6));
                        OverlayItem overlayitem1 = new OverlayItem(point1, mapsearchresults.get(k).getName(), "");

                        itemizedoverlay1.addOverlay(overlayitem1);
                        mapOverlays.add(itemizedoverlay1);

                    }
                    mapView.invalidate();
                    mapsearchresults.clear();

                }

            }

        }
    });

}

}

我的清单文件代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.x.iSenegal"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="com.google.android.maps" />

    <activity android:name=".iSenegal"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Activity1" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Activity2" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Activity3" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Activity4" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Activity5" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Categories" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Results" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Details" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Favoris" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Recherche" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="SearchResults" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>
    <activity android:configChanges="keyboardHidden|orientation" android:screenOrientation="portrait" android:name="Map" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"></activity>


</application>

1 个答案:

答案 0 :(得分:1)

您是否使用谷歌插件进行地图活动(对于您应该使用谷歌插件的地图),检查您是否使用它。如果您使用支票,请使用“导入com.google”行。 android.maps.MapActivity;”在你的源代码“java.util.Map”中,Map和MapActivity都是不同的。你可以发布代码片段以获取更多信息。