我尝试在我有Main活动的地方创建app,在点击Options Item - Map后创建MapActivity。我无法解决这个问题。
02-25 22:39:48.956: E/AndroidRuntime(22525): FATAL EXCEPTION: main
02-25 22:39:48.956: E/AndroidRuntime(22525): android.content.ActivityNotFoundException: Unable to find explicit activity class **{pl.pawelfrydrych.flyingball/pl.pawelfrydrych.flyingball.Map}; have you declared this activity in your AndroidManifest.xml?**
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1645)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1441)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Activity.startActivityForResult(Activity.java:3464)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Activity.startActivityForResult(Activity.java:3425)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Activity.startActivity(Activity.java:3661)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Activity.startActivity(Activity.java:3629)
02-25 22:39:48.956: E/AndroidRuntime(22525): at pl.pawelfrydrych.flyingball.MainActivity.onOptionsItemSelected(MainActivity.java:166)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.Activity.onMenuItemSelected(Activity.java:2640)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1171)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:178)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.widget.AbsListView.performItemClick(AbsListView.java:1510)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3333)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.os.Handler.handleCallback(Handler.java:730)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.os.Handler.dispatchMessage(Handler.java:92)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.os.Looper.loop(Looper.java:137)
02-25 22:39:48.956: E/AndroidRuntime(22525): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-25 22:39:48.956: E/AndroidRuntime(22525): at java.lang.reflect.Method.invokeNative(Native Method)
02-25 22:39:48.956: E/AndroidRuntime(22525): at java.lang.reflect.Method.invoke(Method.java:525)
02-25 22:39:48.956: E/AndroidRuntime(22525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
如果您在AndroidManifest中声明了此活动,我会看到此错误,但我无法做到。
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.Mapy:
Intent intent = new Intent(this,Map.class);
startActivity(intent);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pl.pawelfrydrych.flyingball"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="pl.pawelfrydrych.flyingball.MainActivity"
android:label="@string/app_name" >
<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>
public class Map extends MapActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mapactivity);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setTraffic(false);
mapView.setSatellite(true);
mapView.setStreetView(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:1)
好像你忘了宣布活动:
pl.pawelfrydrych.flyingball.Map
在你的AndroidManifest.xml
中在另一个activity
标记下面的Manifest.xml中添加类似的内容:
<activity
android:name="pl.pawelfrydrych.flyingball.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- add this here: -->
<activity
android:name="pl.pawelfrydrych.flyingball.Map"
android:label="@string/map_title" >
</activity>