android development on options menu


I am new to Android development by using PhoneGap, I try to build an options menu through a tutorial from, but it always gave error messages like below:

[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’).

Here is console code:

package com.phonegap.helloworld;

import android.os.Bundle;
import com.phonegap.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(, menu);
    return true;

public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        return true;
        return true;
        return super.onOptionsItemSelected(item);

public boolean onKeyDown(int keyCode,KeyEvent event){
        if (keyCode == KeyEvent.KEYCODE_MENU) {
           return false;
           return super.onKeyDown(keyCode, event);




<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="">
    <item android:id="@+id/new_game"
      android:title="@string/new_game" />
    <item android:id="@+id/help"
      android:title="@string/help" />

Did anybody tell what cause the errors?

Thanks a lot!

After define string in string.xml, the error gone away but I’ve meet new errors like below

KeyEvent cannot be resolved to a type    /HelloPhoneGap/src/com/phonegap/helloworld  line 39 Java Problem
KeyEvent cannot be resolved to a variable    /HelloPhoneGap/src/com/phonegap/helloworld  line 40 Java Problem
Menu cannot be resolved to a type    /HelloPhoneGap/src/com/phonegap/helloworld  line 17 Java Problem
MenuInflater cannot be resolved to a type    /HelloPhoneGap/src/com/phonegap/helloworld  line 18 Java Problem
MenuItem cannot be resolved to a type    /HelloPhoneGap/src/com/phonegap/helloworld  line 24 Java Problem


you must have define Strings new_game in values like

<string name="new_game">Your String</string>
 <string name="help">Your String</string>

refer this

You can create values xml file -If you are using eclipse then right click on the project and select other and there select android xml file,then given window select resource type as value,

Answered By – sampathpremarathna

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published