如何在Java中解决这种不兼容的类型? [英] How to solve this incompatible types in java?
本文介绍了如何在Java中解决这种不兼容的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误:不兼容的类型
required:java.util.Map。条目< java.lang.String中,java.lang.String中[] GT;
found:java.lang.Object
完整代码低于
package com.auth.actions;
public class SocialAuthSuccessAction extends Action {
final Log LOG = LogFactory.getLog(SocialAuthSuccessAction.class);
$ b @Override
public ActionForward execute(最终ActionMapping映射,
最终ActionForm表单,最终HttpServletRequest请求,$ b $最终HttpServletResponse响应)throws Exception {
AuthForm authForm =(AuthForm)表单;
SocialAuthManager manager = null;
if(authForm.getSocialAuthManager()!= null){
manager = authForm.getSocialAuthManager();
}
if(manager!= null){
List< Contact> contactsList = new ArrayList< Contact>();
配置文件配置文件= null;
尝试{
Map< String,String> paramsMap = new HashMap< String,String>();
for(Map.Entry< String,String []> entry:request.getParameterMap()。entrySet()){//此错误!
String key = entry.getKey();
字符串值[] = entry.getValue();
paramsMap.put(key,values [0] .toString()); //只有1个值是
}
AuthProvider provider = manager.connect(paramsMap);
profile = provider.getUserProfile();
contactsList = provider.getContactList(); (ContactList!= null&& contactsList.size()> 0){
for(Contact p:contactsList){
if(StringUtils.isEmpty(p.getFirstName ))
&& StringUtils.isEmpty(p.getLastName())){
p.setFirstName(p.getDisplayName());
}
}
}
} catch(Exception e){
e.printStackTrace();
}
request.setAttribute(profile,profile);
request.setAttribute(contacts,contactsList);
返回mapping.findForward(success);
}
// if provider null
return mapping.findForward(failure);
$ / code $ / pre
$ b $ p请帮忙
<您需要将 request.getParameterMap()
转换为 Map< String,String
(Map.Entry< String,String []>条目:
((Map< String,String []>)request.getParameterMap())。entrySet())
I get error in following lines.
error: incompatible types
required : java.util.Map.entry<java.lang.String,java.lang.String[]>
found :java.lang.Object
full code is below
package com.auth.actions;
public class SocialAuthSuccessAction extends Action {
final Log LOG = LogFactory.getLog(SocialAuthSuccessAction.class);
@Override
public ActionForward execute(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
AuthForm authForm = (AuthForm) form;
SocialAuthManager manager = null;
if (authForm.getSocialAuthManager() != null) {
manager = authForm.getSocialAuthManager();
}
if (manager != null) {
List<Contact> contactsList = new ArrayList<Contact>();
Profile profile = null;
try {
Map<String, String> paramsMap = new HashMap<String, String>();
for (Map.Entry<String, String[]> entry :request.getParameterMap().entrySet() ) { // error in this line!
String key = entry.getKey();
String values[] = entry.getValue();
paramsMap.put(key, values[0].toString()); // Only 1 value is
}
AuthProvider provider = manager.connect(paramsMap);
profile = provider.getUserProfile();
contactsList = provider.getContactList();
if (contactsList != null && contactsList.size() > 0) {
for (Contact p : contactsList) {
if (StringUtils.isEmpty(p.getFirstName())
&& StringUtils.isEmpty(p.getLastName())) {
p.setFirstName(p.getDisplayName());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("profile", profile);
request.setAttribute("contacts", contactsList);
return mapping.findForward("success");
}
// if provider null
return mapping.findForward("failure");
}
}
Please help
解决方案
You need to cast request.getParameterMap()
to Map<String, String[]>
for (Map.Entry<String, String[]> entry :
((Map<String, String[]>)request.getParameterMap()).entrySet())
这篇关于如何在Java中解决这种不兼容的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文