struts2 getText() 报空指针错误

quxiuer 2010-07-26 02:25:46
msg = getText("error.email.exist"); //此行报错
return "input";



java.lang.NullPointerException
at com.opensymphony.xwork2.util.LocalizedTextUtil.createMissesKey(LocalizedTextUtil.java:240)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findResourceBundle(LocalizedTextUtil.java:219)
at com.opensymphony.xwork2.util.LocalizedTextUtil.getMessage(LocalizedTextUtil.java:604)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findMessage(LocalizedTextUtil.java:645)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:360)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:293)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:173)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:88)
at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:71)
at com.eu3c.struts.account.LoginAction.execute(LoginAction.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)……
...全文
742 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
nyxxlzh 2012-07-09
  • 打赏
  • 举报
回复
请参见我的解决方法:

http://www.lerx.com/html/2012/06/22/025411739.html
xu15605608628 2012-06-13
  • 打赏
  • 举报
回复
java.lang.NullPointerException
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:359)
org.apache.struts2.dispatcher.Dispatcher.cleanUpRequest(Dispatcher.java:751)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:437)

高手们指点下
closewbq 2010-07-26
  • 打赏
  • 举报
回复
1.<constant name="struts.custom.il8n.resources" value="ApplicationResources"></constant>
直接放在src下。
2.在action中直接调用:

addFieldError("属性", this.getText("资源文件中的key",new String[]{"参数"}));
没有参数的话直接写key。

别的就没有什么了。
quxiuer 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 ladybirds2008 的回复:]
debug、。。。。。
[/Quote]

就是这么配置的,出了问题啊
ladybirds2008 2010-07-26
  • 打赏
  • 举报
回复
debug、。。。。。
quxiuer 2010-07-26
  • 打赏
  • 举报
回复
struts.xml中的配置

<constant name="struts.devMode" value="true"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<constant name="struts.objectFactory" value="spring"></constant>
<constant name="struts.custom.il8n.resources" value="com.test.struts.ApplicationResources"></constant>
<constant name="struts.il8n.encoding" value="UTF-8"></constant>
<constant name="struts.il8n.reload" value="true"></constant>


资源文件在com.test.struts包里 文件名都以ApplicationResources开头
ApplicationResources_en.properties
ApplicationResources_ja.properties
ApplicationResources_zh.properties
ApplicationResources.properties


这样设置有问题吗?
rainsilence 2010-07-26
  • 打赏
  • 举报
回复
如果不带Locate表示默认messageResource
rainsilence 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 quxiuer 的回复:]

引用 6 楼 rainsilence 的回复:
消息文件内error.email.exist找不到。
还有可能是消息配置文件路径不对。
还有可能是消息配置文件文件名不对。你是带Locale的。应该在文件名最后加zh_cn等。
看看你文件内部有没有用全角的=等等。


问一下 你是带Locale的 这一句什么意思
[/Quote]

多语言版本。。。Struts默认通过request的也就是浏览器发送的语言字符串来辨认你messageResource的文件名的最后几位是否相同。
查看浏览器Locale的方法:
1)手动法
IE的话,internet选项中外观->语言。

2)Javascript查看法

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">

alert(navigator.userLanguage || navigator.language);
</script>

</head>
<body>

</body>
</html>



lin_qazwsx 2010-07-26
  • 打赏
  • 举报
回复
ding 六楼
yinzisheng 2010-07-26
  • 打赏
  • 举报
回复
你直接在action中用 this.getText("");就可以获取到了
quxiuer 2010-07-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 rainsilence 的回复:]
消息文件内error.email.exist找不到。
还有可能是消息配置文件路径不对。
还有可能是消息配置文件文件名不对。你是带Locale的。应该在文件名最后加zh_cn等。
看看你文件内部有没有用全角的=等等。
[/Quote]

问一下 你是带Locale的 这一句什么意思
rainsilence 2010-07-26
  • 打赏
  • 举报
回复
消息文件内error.email.exist找不到。
还有可能是消息配置文件路径不对。
还有可能是消息配置文件文件名不对。你是带Locale的。应该在文件名最后加zh_cn等。
看看你文件内部有没有用全角的=等等。
小霍夫 2010-07-26
  • 打赏
  • 举报
回复


楼上几位。根本没说到边!

ActionSupport里面的方法 getText();

setTip(getText("operate.success"));

getText("key");



这个是在做国际化的时候用的

在资源文件中如果没有相应的 key : value 那么是会输出原文的!
上面的情况结果

msg = "error.mail.exist"

错误的原因不在这里:
1:
你的资源文件:

2: 有没设置好 在strust.xml里面配的

如 <constant name="struts.custom.i18n.resources" value="message" />







quxiuer 2010-07-26
  • 打赏
  • 举报
回复
声明一下 我用的是struts2, action继承ActionSupport就有这个getText方法了
这是要去资源文件里面的东西啊
Epiphone 2010-07-26
  • 打赏
  • 举报
回复
getText("error.email.exist"); 这段方法帖出来看看撒
逍遥则子 2010-07-26
  • 打赏
  • 举报
回复

getText重名了吧。 或者说你没有定义text 的get set 方法吧。不行的话 你把你的
代码 粘出来 瞅瞅。
quxiuer 2010-07-26
  • 打赏
  • 举报
回复
up up up

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧