Error: java.lang.ClassCastException

Posted by theJava on Stack Overflow See other posts from Stack Overflow or by theJava
Published on 2011-01-10T11:58:52Z Indexed on 2011/01/10 13:53 UTC
Read the original article Hit count: 271

Filed under:
|
|

Updating the entire post.

public Login authenticate(Login login) {
        String query = "SELECT email, id FROM Login WHERE email=? AND password=?";
        Object[] parameters = { login.getEmail(), login.getPassword() };
        List resultsList = getHibernateTemplate().find(query,parameters);
        if ( resultsList.size() == 1 ) {
        results = (Login)resultsList.get(0);
        System.out.println(results);
        } else {
            System.out.println("Error dude.... ");
        // error no entity or mutiple entities
        }
        return results;
}

I now return Login Objects.

private void checkLogin() {
        form.commit();

        Login newUser = new Login();
        newUser = ilogin.authenticate(loginbean);
        System.out.println("Its Null Value" + newUser);
        if (newUser == null) {
            getWindow().showNotification("Login failed", LOGIN_ERROR_MSG,
                    Notification.TYPE_WARNING_MESSAGE);
        } else {
            System.out.println(newUser);
            getApplication().setUser(newUser);
        }
    }

When there is no matching email, i get there is no such user and also this statement does get printed out. System.out.println("Its Null Value" + newUser);

But when there is a email and password matching. I get weird error.

Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.intermedix.domain.Login
        at com.intermedix.services.LoginService.authenticate(LoginService.java:30)
        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)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy32.authenticate(Unknown Source)
        at com.intermedix.ui.LoginDailog.checkLogin(LoginDailog.java:106)
        at com.intermedix.ui.LoginDailog.access$0(LoginDailog.java:102)
        at com.intermedix.ui.LoginDailog$1.buttonClick(LoginDailog.java:52)
        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)
        at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
        ... 26 more

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate