我有一個主類啓動(或至少這是我想要發生的)兩個其他類的應用程序。主類WhenIGetToActivity
啓動第一類CreateLoc
,但沒有發生錯誤,但在嘗試啓動第二個Menu
時拋出ActivityNotFoundException。ActivityNotFoundException啓動清單中的類
下面是從WhenIGetToActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Intent myIntent = new Intent(getApplicationContext(), Menu.class);
startActivity(myIntent);
return true;
}
...
public boolean onTap(final GeoPoint p, final MapView mapView) {
boolean tapped = super.onTap(p, mapView);
if (tapped) {
Intent myIntent = new Intent(getApplicationContext(), CreateLoc.class);
startActivity(myIntent);
} else {
兩個次級類在正確的(和相同)封裝相關的代碼,既extends Activity
。
這裏是我的清單文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="SandS.Geo.Cal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
<application>
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".WhenIGetToActivity"
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>
<activity android:name="CreateLoc" >
</activity>
<activity android:name="Menu" >
</activity>
</application>
這裏是logcat的
06-21 17:30:21.479: I/ApplicationPackageManager(3891): cscCountry is not German : XEU
06-21 17:30:22.289: W/TAG(3891): Location unknown
06-21 17:30:22.329: I/MapActivity(3891): Handling network change notification:CONNECTED
06-21 17:30:22.329: E/MapActivity(3891): Couldn't get connection factory client
06-21 17:30:27.189: W/KeyCharacterMap(3891): No keyboard for id 0
06-21 17:30:27.189: W/KeyCharacterMap(3891): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-21 17:30:27.229: D/AndroidRuntime(3891): Shutting down VM
06-21 17:30:27.229: W/dalvikvm(3891): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-21 17:30:27.239: E/AndroidRuntime(3891): FATAL EXCEPTION: main
06-21 17:30:27.239: E/AndroidRuntime(3891): android.content.ActivityNotFoundException: Unable to find explicit activity class {SandS.Geo.Cal/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.Activity.startActivityForResult(Activity.java:2827)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.Activity.startActivity(Activity.java:2933)
06-21 17:30:27.239: E/AndroidRuntime(3891): at SandS.Geo.Cal.WhenIGetToActivity.onCreateOptionsMenu(WhenIGetToActivity.java:62)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.Activity.onCreatePanelMenu(Activity.java:2158)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:325)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:570)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1220)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1727)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2627)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2602)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.view.ViewRoot.handleMessage(ViewRoot.java:1874)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.os.Looper.loop(Looper.java:130)
06-21 17:30:27.239: E/AndroidRuntime(3891): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-21 17:30:27.239: E/AndroidRuntime(3891): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 17:30:27.239: E/AndroidRuntime(3891): at java.lang.reflect.Method.invoke(Method.java:507)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-21 17:30:27.239: E/AndroidRuntime(3891): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-21 17:30:27.239: E/AndroidRuntime(3891): at dalvik.system.NativeStart.main(Native Method)
我曾嘗試清洗項目。
任何想法。
從4個回答,我改變類的名稱下面的建議,我已經在這樣做,現在所謂的StevesToolsMenu.class
新onCreateOptionsMenu
現在有行:
Intent myIntent = new Intent(getApplicationContext(), StevesToolsMenu.class);
的相關部分清單文件是現在:
<application>
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".WhenIGetToActivity"
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>
<activity android:name=".CreateLoc" >
</activity>
<activity android:name=".StevesToolsMenu" >
</activity>
</application>
新logcat的是:
06-23 15:14:22.989: I/ApplicationPackageManager(4088): cscCountry is not German : XEU
06-23 15:14:23.789: W/TAG(4088): Location unknown
06-23 15:14:23.849: I/MapActivity(4088): Handling network change notification:CONNECTED
06-23 15:14:23.849: E/MapActivity(4088): Couldn't get connection factory client
06-23 15:14:30.219: W/KeyCharacterMap(4088): No keyboard for id 0
06-23 15:14:30.219: W/KeyCharacterMap(4088): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
06-23 15:14:30.289: I/ApplicationPackageManager(4088): cscCountry is not German : XEU
06-23 15:14:30.319: D/AndroidRuntime(4088): Shutting down VM
06-23 15:14:30.319: W/dalvikvm(4088): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-23 15:14:30.329: E/AndroidRuntime(4088): FATAL EXCEPTION: main
06-23 15:14:30.329: E/AndroidRuntime(4088): java.lang.RuntimeException: Unable to start activity ComponentInfo{SandS.Geo.Cal/SandS.Geo.Cal.StevesToolsMenu}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.os.Looper.loop(Looper.java:130)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-23 15:14:30.329: E/AndroidRuntime(4088): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 15:14:30.329: E/AndroidRuntime(4088): at java.lang.reflect.Method.invoke(Method.java:507)
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-23 15:14:30.329: E/AndroidRuntime(4088): at dalvik.system.NativeStart.main(Native Method)
06-23 15:14:30.329: E/AndroidRuntime(4088): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.Activity.setContentView(Activity.java:1657)
06-23 15:14:30.329: E/AndroidRuntime(4088): at SandS.Geo.Cal.StevesToolsMenu.onCreate(StevesToolsMenu.java:20)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-23 15:14:30.329: E/AndroidRuntime(4088): ... 11 more
06-23 15:14:30.329: E/AndroidRuntime(4088): Caused by: java.lang.reflect.InvocationTargetException
06-23 15:14:30.329: E/AndroidRuntime(4088): at java.lang.reflect.Constructor.constructNative(Native Method)
06-23 15:14:30.329: E/AndroidRuntime(4088): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
06-23 15:14:30.329: E/AndroidRuntime(4088): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
06-23 15:14:30.329: E/AndroidRuntime(4088): ... 21 more
06-23 15:14:30.329: E/AndroidRuntime(4088): Caused by: java.lang.IllegalArgumentException: MapViews can only be created inside instances of MapActivity.
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.google.android.maps.MapView.<init>(MapView.java:291)
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.google.android.maps.MapView.<init>(MapView.java:264)
06-23 15:14:30.329: E/AndroidRuntime(4088): at com.google.android.maps.MapView.<init>(MapView.java:247)
06-23 15:14:30.329: E/AndroidRuntime(4088): ... 24 more
我們似乎已經用另一個問題代替了一個問題(或者更確切地說,發現了第二個問題)。
無論從哪個角度來看,我仍然很難理解爲什麼一個類應該工作而另一個類(看起來是相同的方式安裝)沒有。
我不確定你在這裏的意思。首先,這個活動被稱爲'SandS.Geo.Cal.Menu',因爲我希望它被命名爲;我已將其更改爲'SandS.Geo.Cal.StevesToolsMenu',以防止與View.Menu衝突。其次,如果你花時間看看,你會發現我的Intent構造函數的第二個參數是'Menu.class'(現在是'StevesToolsMenu.class')。 –
@ steve.watson128:「其次,如果你花時間看看,你會看到我的Intent構造函數的第二個參數是Menu Menu。」 - 我*做*花時間看看。然而,你顯然沒有。您的錯誤消息是「無法找到明確的活動類{SandS.Geo.Cal/android.view.Menu}'。注意對'android.view.Menu'的引用。這是因爲你試圖啓動'android.view.Menu'作爲一個activity,因爲你的'Menu.class'引用解決了'android.view.Menu',因爲你正在導入'android.view.Menu'和不是你自己的菜單類。 – CommonsWare
@ steve.watson128:關於您的新錯誤,「MapViews只能在MapActivity的實例中創建」是一個相當直接的錯誤消息。 Android認爲無論你在膨脹什麼佈局的第17行,都會引用'MapView',並且你的'StevesToolMenu'不是'MapActivity'。如果您確信您的佈局未引用MapView,請嘗試清理項目(Eclipse中的項目> Clean或命令行開發中的ant clean),因爲偶爾Android的資源ID引用不同步。 – CommonsWare