2014-01-24 44 views
0

我的应用程序和eclipse出现问题,所以我保存了我的代码,删除了eclipse,然后重新下载并解压。在我将XML文件添加到res/menu后,立即收到一条窗口消息,说aapt.exe已停止工作;我之前不断收到这个消息。我之前就研究过它,所以我知道如果XML文件写入不正确,aapt.exe会一直崩溃。唯一的是,我没有看到文件的问题。这个XML文件有什么问题? (不断崩溃aapt.exe)

createlgmenu.xml(用作弹出菜单的按钮事件):

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:id="@+id/Create_List" 
     android:title="@string/Create_List"/> 

    <item 
     android:id="@+id/Create_Food_Group" 
     android:title="@string/Create_Food_Group"/> 

</menu> 

|

|

其他文件:

我在mainactivity.java几乎没有代码:

package com.example.groceryrunner; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.PopupMenu; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 


    public void onCreateLGClick(View v) { 
     final int id = v.getId(); 
     switch (id) { 
     case R.id.CreateLG: 
      //findViewById(R.id.GetStarted).setVisibility(View.INVISIBLE); 
      createLGPopup(v); 
      break; 
     /*case R.id.ListsButton: 
      findViewById(R.id.GetStarted).setVisibility(View.INVISIBLE); 
      createLGMenu(v); 
      break;*/ 
     } 
    } 

    public void createLGPopup(View v) { 
     PopupMenu LGMenu = new PopupMenu(this, v); 
     LGMenu.getMenuInflater().inflate(R.menu.createlgmenu, LGMenu.getMenu()); 
     LGMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 

      @Override 
      public boolean onMenuItemClick(MenuItem item) { 
       String choice = new String((String) item.getTitle()); 
       if (choice == "Create_List") { 
        //createListDialog(); 
       } 
       else if (choice == "Create_Group") { 
        //createListDialog(); 
       } 
       return false; 
      } 
     }); 
     LGMenu.show(); 
    } 

} 

只有一个按钮,在我的activity_main.xml中至今:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <Button 
     android:id="@+id/CreateLG" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="37dp" 
     android:layout_marginTop="21dp" 
     android:text="+" 
     android:textSize="40sp" /> 

</RelativeLayout> 

如果您希望看到我的menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@+id/action_settings" 
     android:orderInCategory="100" 
     android:showAsAction="never" 
     android:title="@string/action_settings"/> 

</menu> 
+0

你是否改变了android:id =“@ id/Create_List”到android:id =“@ + id/Create_List”之类的东西,我看到你的menu.xml是正确的,请尝试清理你的项目。 – Jorgesys

+0

不,它总是说@ + id。另外,当我的res/menu中有createlg_menu.xml时,我似乎无法清理我的项目,因为不是清理项目,而是aapt.exe再次停止工作。如果我删除createlg_menu.xml,项目会自行清理。 我还应该说我的MainActivity.java永远不会检测到createlg_menu(最初称为createlgmenu),它认为它不存在。它也没有说其他的东西存在,比如CreateLG,我唯一的按钮id(它曾经很好..)。 – user2100364

回答

0

我想我找到了我的解决方案。

我已经复制了xml,并且自己更改了项目。所以我删除它并通过Eclipse创建它(右键单击res/menu文件夹>新建>其他> Android XML文件>菜单)。我不再似乎得到appt.exe错误。然后我使用Eclipse 添加了这些项目,而不是自己编写或复制它们的

在这两个文件中的唯一的区别是旧的结束了这个每个项目:

\> 

而且通过Eclipse中创建一个使用这个在项目申报结束:

></item> 

至于Eclipse中不承认我的XML文件,ADAMM帮我找到了解决这一问题还有: 1)我删除将R进口

2)评论指出,是给我的错误,承认我的XML文件

3)重启动Eclipse的&内置所有

1

如果您使用的是支持库和库项目,那么你需要一个自定义命名为“线showAsAction“标签用于较旧的平台版本。

所以更改此设置:

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:id="@+id/action_settings" 
     android:orderInCategory="100" 
     android:showAsAction="never" 
     android:title="@string/action_settings"/> 

</menu> 

要这样:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:custom="http://schemas.android.com/apk/res-auto" > 

    <item 
     android:id="@+id/action_settings" 
     android:orderInCategory="100" 
     custom:showAsAction="never" 
     android:title="@string/action_settings"/> 

</menu> 

注意, “定制” 可以是任何你想要。