简体   繁体   English

Android资源未找到异常

[英]Android Resource not found exception

So I am not such a newbie in Programming, Java or Android developing, but I got a strange issue: I have made an application, quite advanced, and have it on market. 所以我不是编程,Java或Android开发中的新手,但我遇到了一个奇怪的问题:我已经制作了一个应用程序,非常先进,并且已经在市场上销售。

For now I have over 1000 installs and I have around 4 or 5 crash reports for a ResourceNotFoundException. 目前我有超过1000个安装,我有大约4或5个针对ResourceNotFoundException的崩溃报告。 The strangest thing is that the line it crashes on is on 最奇怪的是它崩溃的线是打开的

setContentView(R.layout.some_custom_layout)

In code I am always referring to resourced by 在代码中我总是指资源

someTxtView.setText(R.string.some_string)

So I am wondering if I used 所以我想知道我是否使用过

mContext.getResources().getDrawable(mContext.getResources().getIdentifier("some_string", "string", "my.example.package"));

would the crash go away? 崩溃会消失吗?

I was facing the same issue and I fixed it by creating Layout Folder called "layout-small". 我遇到了同样的问题,我通过创建名为“layout-small”的布局文件夹来修复它。

Based on resolutions I have created only 2 folders "layout-large" and "layout-medium". 根据分辨率我只创建了2个文件夹“layout-large”和“layout-medium”。 But few phones are having lower resolution it doesn't find proper resources as per the resolution. 但很少有手机具有较低的分辨率,因此根据分辨率找不到合适的资源。 Android OS renders xml resources as per resolution. Android OS根据分辨率呈现xml资源。 It goes and find the resources in required folders. 它去找所需文件夹中的资源。

95+ % Android phones having resolution which matches "layout-normal" folder. 95%以上的Android手机,其分辨率与“layout-normal”文件夹相匹配。 But still there are Phones having lower resolution. 但仍有手机具有较低的分辨率。 Hence this issue occurred. 因此出现了这个问题。

For more Details : http://developer.android.com/guide/practices/screens_support.html 有关详细信息,请访问: http//developer.android.com/guide/practices/screens_support.html

Hope this helps your problem. 希望这有助于你的问题。

someTxtView.setText(R.string.some_string)

There you set integer value to text. 在那里你设置整数值到文本。 Its not correctly becouse it search a resousre on this value. 它不正确因为它搜索这个值的resousre。 You must write 你必须写

someTextView.setText(getResources().getText(R.string.blabla));

If you are calling setContentView(R.layout.some_custom_layout) from the Activity's onCreate method, you should be good as long as your app compiles (and I assume it does). 如果你从Activity的onCreate方法调用setContentView(R.layout.some_custom_layout) ,只要你的应用程序编译(我认为它确实如此)你应该是好的。

AFAIK accessing your string resources via: AFAIK访问您的字符串资源:

someTxtView.setText(R.string.some_string)

is not the way to go. 不是要走的路。 You should be doing this: 你应该这样做:

getContext().getResources().getString(R.string.some_string)

Except 除了

setContentView(R.layout.some_custom_layout);

try using 尝试使用

setContentView(yourpackagename.R.layout.some_custom_layout);

that helped me a lot of times. 这帮助了我很多次。

I have one suggestion. 我有一个建议。 Do you use in your layouts android secific resources, such as drawables or something, for example 你是否在你的布局中使用android secific资源,例如drawables或者其他东西

android:backgroud="@android:drawable/some_android_drawable" 机器人:研究背景= “@机器人:可绘制/ some_android_drawable”

Maybe some vendors don't provide some resources with their firmware, so your app crashs. 也许某些供应商不提供其固件的一些资源,因此您的应用程序崩溃。 for example this issue 例如这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM