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-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org

Reply via email to