ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: New to iBatis facing problem to get started
Date Thu, 31 Dec 2009 15:50:18 GMT
You can sort of tell given his output:

    *PROFILE null*
    Exception in thread "main" java.lang.NullPointerException
           at Main.main(Main.java:23)

So given that:

21.    ...
22.    System.out.println(*"PROFILE " + profile*);
23.    System.out.println(profile.getName());
24.    ...

We take NPE very seriously, and consider any NPE thrown by iBATIS to be a
but.  This however, is not being thrown by iBATIS.  There is simply no
profile object returned, and he's calling getName() against a null
reference.

Clinton

On Wed, Dec 30, 2009 at 10:38 PM, Guy Rouillier <guyr-ml1@burntmail.com>wrote:

> On 12/30/2009 12:28 AM, vishalj wrote:
>
>>
>> Hi,
>> I am using iBatis for the first time ,but no success yet.This is how my
>> setup looks like
>>
> ...
>
>  String resource = "com/pg/ibatis/config/Configuration.xml";
>>                Reader reader = Resources.getResourceAsReader(resource);
>>                SqlSessionFactory factory = new SqlSessionFactoryBuilder()
>>                                .build(reader);
>>                SqlSession session = factory.openSession();
>>                try {
>>                        UserProfileMapper mapper =
>> session.getMapper(UserProfileMapper.class);
>>                        UserProfile profile = mapper.selectUserProfile(1);
>>                        System.out.println("PROFILE " + profile);
>>                        System.out.println(profile.getName());
>>                } finally {
>>                        session.close();
>>                }
>>
>> But i am getting NPE
>> PROFILE null
>> Exception in thread "main" java.lang.NullPointerException
>>        at Main.main(Main.java:23)
>>
>
> Well, put in a catch clause and print a stack trace.  Hard to tell where
> the error is occurring, since you are not showing complete source, so we
> have no idea where line 23 is.
>
> Though the execution is printing out your first System.out, I'm guessing
> the error is much earlier.  My guess would be that it can't find your
> Configuration.xml file.  Are your running within an IDE?  Debug and single
> step through to make sure that the factory, session and mapper objects are
> all getting created successfully.
>
> --
> Guy Rouillier
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Mime
View raw message