在Android Titanium模块中访问图像时出现ResourceNotFoundException错误

时间:2016-04-07 15:09:16

标签: titanium appcelerator appcelerator-titanium

我正在为Titanium应用开发Android模块,我必须生成通知。 Android SDK强制我进行setSmallIcon()调用,将png资产包含为通知的图标。我把 icon_notification.png 资产放在我模块的 / platform / android / res / drawable 文件夹中,并且(试着)在代码调用中得到它

TiRHelper.getResource("drawable.icon_notification")

但是当我构建模块调用ant时,会引发以下错误:

[javac] Note: [KrollBindingGen] Running Kroll binding generator.
[javac] Note: [KrollBindingGen] No binding data found, creating new data file: org.appcelerator.titanium.bindings/connecthings.json
[javac] Note: [KrollBindingGen] Found binding for proxy Beacon
[javac] Note: [KrollBindingGen] Found binding for module Connect
[javac] Note: [KrollBindingGen] Generating JSON: file:/Users/***/Development/***/modules/android/***/android/build/generated/json/org/appcelerator/titanium/bindings/***.json
[javac] warning: The following options were not recognized by any processor: '[kroll.checkTiContext]'
[javac] /Users/***/Development/***/modules/android/***/android/src/***/***/***/***/ConnectModule.java:76: error: unreported exception ResourceNotFoundException; must be caught or declared to be thrown
[javac]             .setSmallIcon(TiRHelper.getResource("drawable.icon_notification"))
[javac]                                                ^
[javac] Note: /Users/***/Development/***/modules/android/***/android/src/***/***/ti/***/BeaconProxy.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 error

似乎提出ResourceNotFoundException异常,构建器找不到assset

我是否将文件放在错误的位置?

2 个答案:

答案 0 :(得分:0)

平台文件夹也有android文件夹的子文件夹。完整目录是“android / platform / android / res / drawable /”。您还可以检查是否在构建文件夹中创建了资源。

Documentation Link

答案 1 :(得分:0)

在模块的构建步骤中,已发布错误。 在这一步中,我认为资源尚未到位,因此,将@Taeed Sharman建议的wiki中编写的try ... catch语句中的TiRHelper方法包装解决问题。

所以,工作版本只是:

try {
  TiRHelper.getResource("drawable.icon_notification");
catch (ResourceNotFoundException e) {
  ...
}