Type Cast Owned :( [[Ljava.lang.String; cannot be cast to java.lang.String]

1 resposta
Mikhas

Hey galera!

Estava aqui trabalhando com uns ServletRequest etc e tal.
Quando fui obter os parametros da requisisão eu recebo o incrivel erro:

Eis meu código:

@SuppressWarnings("unchecked")
	private Object getModelParameter(ModelParameter modelParameter, Parameter param, HttpServletRequest req) {
		String alias = modelParameter.value();
		Set<Entry<String, String>> params = (Set<Entry<String, String>>) req.getParameterMap().entrySet();

		ObjectTargetedReflector otr = Spectrum.with(param.getType()).withInstance();

		String modelAttribute;

		for (Entry<String, String> requestAttribute : params) {

			if (requestAttribute.getKey().startsWith(alias + ".")) {
				System.out.println(requestAttribute.getValue());
				/*
				 * String modelAttributeValue = requestAttribute.getValue(); modelAttribute =
				 * requestAttribute.getKey().substring(alias.length() + 1); modelAttribute = modelAttribute.substring(0,
				 * 1).toUpperCase() + modelAttribute.substring(1);
				 * 
				 * ObjectMethodHandler omh = otr.method("set" + modelAttribute); Class<?> attributeType = omh.getReturnType();
				 * 
				 * Object value = this.convertStringToType(modelAttributeValue, attributeType);
				 * 
				 * omh.invoke(value);
				 */
			}
		}
		return otr.getObject();
	}

Para isso ai… eu não tenho a minima idea do que pode ser :frowning:

1 Resposta

T

[Ljava.lang.String; cannot be cast to java.lang.String

quer dizer:

Você tem um String[] e tentou fazer um cast para String.

Portanto, faça o cast para String[], e trate o array de string resultante.

Criado 28 de maio de 2009
Ultima resposta 28 de mai. de 2009
Respostas 1
Participantes 2