【发布时间】:2012-01-01 17:31:45
【问题描述】:
我试图让我的菜单充气器链接到我的布局文件,但是当应用程序启动并且我点击菜单时,然后选择菜单选项它会导致程序崩溃。它说它找不到要启动的活动:
eclipse LogCat 中的错误:
01-01 10:24:38.799: E/AndroidRuntime(30359): java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.menu/com.menu.AboutUs}: java.lang.ClassNotFoundException: com.加载器dalvik.system.PathClassLoader中的menu.AboutUs[/data/app/com.menu-1.apk]
主代码:
package menu;
import com.menu.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.MenuItem;
public class testActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.new_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.aboutUs:
Intent i = new Intent("menu.ABOUT");
startActivity(i);
break;
case R.id.settings:
break;
}
return false;
}
清单代码:
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name="menu.testActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AboutUs"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
<intent-filter >
<action android:name="menu.ABOUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
about.xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:text="Why dosent this work??????????????????????? "
android:title="About Us"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
非常感谢您的帮助...谢谢
【问题讨论】:
-
您是否在意图过滤器中为要在单击菜单选项时启动的活动添加了操作“menu.ABOUT”?还可以尝试删除“。”在 menu.ABOUT 中并使用说 menu_ABOUT
-
但是菜单是包,我只是在标明ABOUT所在的位置没有?