语法错误,如果我不导入android.R(和语法错误,如果我这样做) [英] syntax error if I don't import android.R (and syntax error if I do)

查看:129
本文介绍了语法错误,如果我不导入android.R(和语法错误,如果我这样做)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个问题,我太糊涂了正常要求,但这里一展身手:

OK, I have a question I'm too confused to ask properly but here's a go:

在某处Android文档中它指出:

Somewhere in the android documentation it states:

注:月食有时喜欢在你的文件使用资源的顶部添加一个进口android.R的声明,尤其是当你问蚀进行排序或管理进口。这将导致你的化妆打破。查找出这些错误import语句并删除它们。

我以前看到这种行为。第一次是一个非常糟糕的经历,因为我不明白发生了什么事情。反正从那以后,每当我看到进口android.R;我只是删除它。

I've noticed this behavior before. The first time was a very bad experience because I couldn't understand what was going on. Anyway since then whenever I notice import android.R; I just delete it.

我最近的项目中使用最新的SDK,包括其主 - 详细活动向导(创建片段)。我注意到在我的ListFragment源文件导入android.R;然后删除它打破了它,因为它显然需要android.R使用中的onCreate内置的布局simple_list_item_activated_1(http://developer.android.com/reference/android/R.layout.html#simple_list_item_activated_1)。

My most recent project used the latest SDK including the Master - Detail Activity wizard (that creates fragments). I noticed in my ListFragment source file import android.R; and then deleted it which broke it because it apparently needs android.R to use the built in layout "simple_list_item_activated_1" (http://developer.android.com/reference/android/R.layout.html#simple_list_item_activated_1) in onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
            R.layout.simple_list_item_activated_1,
            R.id.text1,
            DummyContent.ITEMS));
}

所以我添加回去,它的罚款。问题是与android.R包括我看不到我的任何定义的XML的东西。就我而言,我试图用我onCreateOptionsMenu创建了一个菜单。

So I add it back and it's fine. The problem is with android.R included I can't see any of my defined XML stuff. In my case I'm trying to use a menu I created in onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    //MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_checklist_list, menu);
    R.layout.
}

所以我的问题是,如果我不进口android.R那么的onCreate破产了,如果我做进口android.R然后onCreateOptionsMenu破产了。如果我不该死,该死的,如果我不知道。的哭声

:(

推荐答案

这通常是因为发生了:


  1. 使用的Eclipse ADT有一些错误。

  2. 您正在使用的R资源从android.R文件。

要解决此问题,删除进口android.R 语句。现在有些错误会去,如果错误是因为#2,一些新的上来了。滚动到新的错误。他们应该是线条状:

To fix this, remove the import android.R statement. Now some errors will go, and if the error was because of #2, some new ones will come up. Scroll to the new errors. They should be lines like:

R.layout.simple_list_item_activated_1

现在只需preFIX 机器人。来的R变量,该错误将消失。

Now simply prefix android. to that R variable, and the error will go away.

此外,你应该每一个涉及到R档的错误发生时清理项目。

Also, you should clean the project every time an error related to the R file happens.

这篇关于语法错误,如果我不导入android.R(和语法错误,如果我这样做)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆