Android的工作室编译错误添加了resouces [英] Android Studio compile error with added resouces

查看:183
本文介绍了Android的工作室编译错误添加了resouces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入这行code到我的程序:

I have added this line of code to my program:

icon1.setImageResource(getResources().getIdentifier(item1, "drawable", getApplicationContext().getApplicationInfo().packageName));

和添加图像文件(.png)我绘制文件夹。当我编译我收到以下错误:

And have added images (.png) to my drawable folder. When I compile I get the following error:

Error:(773, 32) error: <identifier> expected
Error:(773, 37) error: illegal start of type

在R.java错误的位置:

The error location in R.java:

public static final class drawable {
        public static final int 1001=0x7f020000;
        public static final int 1004=0x7f020001;
        public static final int 1006=0x7f020002;
        public static final int 1011=0x7f020003;
        public static final int 1018=0x7f020004;
        public static final int 1026=0x7f020005;
        public static final int 1027=0x7f020006;
        ..........

这些中的每一个抛出了自己对这些错误的。

Each one of those throws its own pair of those errors.

我把图像插入/ RES /绘,华电国际的文件夹。是的问题,文件名是所有的数字(例如1023.png)?

I'm putting the images into the /res/drawable-hdpi folder. Is the issue that the file names are all numeric (ex. 1023.png)?

什么可能是这个原因吗?

What could be the cause of this?

推荐答案

该行这样的:

public static final int 1001=0x7f020000;

说的声明与类型的变量 INT 名为 1001 键,其值为 0x7f020000 。名称应标识(包括人物的 A - 以Z A - 以Z _ 0 - 9 只被第一个字符后允许的)。

are saying "declare a variable with type int whose name is 1001 and whose value is 0x7f020000". Names should be identifiers (consisting of the characters a-z, A-Z or _, with 0-9 being allowed only after the first character).

在这种情况下, 1001 是一个整数不是标识符,这就是为什么你会得到预期的错误。 非法启动类型的错误指的是相同的问题(编译器期待的识别符,以提供该类型的名称)。

In this instance, 1001 is an integer not an identifier, which is why you get the " expected" error. The "illegal start of type" error is referring to the same issue (the compiler is expecting an identifier to provide the name of the type).

R.java的项目应该是这样的话:

public static final int actionbar_logo=0x7f020000;

提拉标识是从文件名创建,为你的数字文件名是使用这些值。你应该给图像明智的名称或preFIX追加到他们,例如 r1023

这篇关于Android的工作室编译错误添加了resouces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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