我是新來的Android開發利用的PhoneGap,我試圖通過從http://developer.android.com/guide/topics/ui/menus.html教程建立一個選項菜單,但它總是給錯誤信息象下面這樣:選項菜單上的Android開發
[2011-12-20 16:45:28 - HelloPhoneGap] W/ResourceType(23444): Bad XML block: header size >84 or total size 0 is larger than data size 0 [2011-12-20 16:45:28 - HelloPhoneGap] C:..\workspace\HelloPhoneGap\res\menu\menu.xml:3: >error: Error: No resource found that matches the given name (at 'title' with value >'@string/new_game'). [2011-12-20 16:45:28 - HelloPhoneGap] C:..\workspace\HelloPhoneGap\res\menu\menu.xml:5: >error: Error: No resource found that matches the given name (at '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
謝謝,錯誤消失了,但新的錯誤信息出來了,請參考我編輯過的帖子 – conmen 2011-12-20 09:57:22
看來你已經忘記添加導入這個.... import android.view.KeyEvent; – sampathpremarathna 2011-12-21 03:41:08