Firefox 插件的奇怪行为
我有一个首选项条目并使用下面的语句来访问它的内容,
var st = easyfa.branch.getComplexValue("mapstr",Components.interfaces.nsIPrefLocalizedString).data;
这会引发异常:
*Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIPrefBranch.getComplexValue]*
但是在手动设置首选项的值(通过输入 about:config)后,错误消失了!?
I have a preference entry and use below statement to access it's content
var st = easyfa.branch.getComplexValue("mapstr",Components.interfaces.nsIPrefLocalizedString).data;
this throws exception:
*Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIPrefBranch.getComplexValue]*
But after setting value of the preference manually (by entering about:config) the error disappears!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本地化首选项的默认值必须是
.properties
文件的 chrome URL,在该文件中查找首选项以找到结果字符串。假设 URL 指向区域设置文件,则该值可以根据安装的语言进行更改。然而,您似乎想要一个简单的字符串首选项,您应该使用 nsISupportsString 接口来检索它。
The default value of a localised preference must be a chrome URL to a
.properties
file, in which the preference is looked up to locate the resulting string. Assuming the URL points to a locale file, this allows the value to change depending on the installed language.However you seem to want a simple string preference, which you should retrieve using the
nsISupportsString
interface.获取未设置的首选项的值总是会抛出异常。您必须将其包装在 try-catch 块中并进行相应的处理。
Getting the value of a preference that isn't set will always throw. You have to wrap it in a
try-catch
block and handle it accordingly.