我是使用PhoneGap进行Android开发的新手,我尝试通过http://developer.android.com/guide/topics/ui/menus.html的教程构建选项菜单,但它总是给出如下错误消息:
[2011-12-20 16:45:28 - HelloPhoneGap] W / ResourceType(23444):错误的XML块:标题大小> 84或总大小0大于数据大小0 [2011-12-20 16:45:28 - HelloPhoneGap] C:.. \ workspace \ HelloPhoneGap \ res \ menu \ menu.xml:3:>错误:错误:找不到与给定名称匹配的资源(在' title'with value>'@ string / new_game')。 [2011-12-20 16:45:28 - HelloPhoneGap] C:.. \ workspace \ HelloPhoneGap \ res \ menu \ menu.xml:5:>错误:错误:找不到与给定名称匹配的资源(在' title'with value>'@ string / help')。
这是控制台代码:
package com.phonegap.helloworld;
import android.os.Bundle;
import com.phonegap.*;
public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/jqm/index.htm");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_MENU) {
return false;
}else{
return super.onKeyDown(keyCode, event);
}
}
}
menu.xml文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/new_game"
android:title="@string/new_game" />
<item android:id="@+id/help"
android:title="@string/help" />
</menu>
有人说出导致错误的原因吗?
非常感谢!
在string.xml中定义字符串后,错误消失但我遇到了如下所示的新错误
KeyEvent cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 39 Java Problem
KeyEvent cannot be resolved to a variable App.java /HelloPhoneGap/src/com/phonegap/helloworld line 40 Java Problem
Menu cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 17 Java Problem
MenuInflater cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 18 Java Problem
MenuItem cannot be resolved to a type App.java /HelloPhoneGap/src/com/phonegap/helloworld line 24 Java Problem
答案 0 :(得分:1)
好像你错过了/res/values/strings.xml 您的文本应该有以下字符串标记:
<string name="help">Help</string>
<string name="new_game">New game</string>
答案 1 :(得分:1)
您必须在
等值中定义字符串new_game
<resources>
<string name="new_game">Your String</string>
<string name="help">Your String</string>
</resources>
参考this
你可以创建值xml文件 - 如果你正在使用eclipse然后右键单击项目并选择其他并选择android xml文件,然后给出窗口选择资源类型作为值,
答案 2 :(得分:0)
您似乎在strings.xml
字符串new_game
和help