Results 1 to 4 of 4
  1. #1
    kirangk is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Null pointer exception in hibernate

    hi everyone
    i have an issue, its an coding problem and i know its an silly mistake but i am new to this i am not able to solve so please any one help me in solving this,

    I made a query to the DB and got an object which contains 2 data, i tried retreiving it using string array the compiles without an error but while executing it gives NULL POINTER EXCEPTION. I think i did some mistake while retreiving it so please can anyone give proper code to retreive data ???
    The error message is as below,

    [SRC]# java UDPServer
    Opening a connection to database
    Starting to listen for data to persist to database.
    entering main
    configuration is done
    connection got
    query executed
    Coefficent 1 is :0.032 // this 2 are retrieved data from DB
    Coefficent 0 is :-23.82
    Device ID is : 201001000006
    Sensor type is : HUM
    exception occured
    java.lang.NullPointerException
    at FetchCoeff.testing(FetchCoeff.java:51)
    at UDPServer.main(UDPServer.java:70)
    Exception in thread "main" java.lang.NullPointerException
    at UDPServer.main(UDPServer.java:72)



    The code is


    import java.util.Iterator;

    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    import org.hibernate.HibernateException;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;



    public class FetchCoeff {
    public String[] testing(String x, String y) { ///here x=DevID and y= sensor type
    Session session= null ;
    Transaction tx= null;
    String c[] = null;


    System.out.println("entering main");
    Logger.getRootLogger().setLevel(Level.OFF);
    Configuration cfg= new Configuration();
    cfg.configure("Hibernate.cfg.xml");
    System.out.println("configuration is done");
    session = cfg.buildSessionFactory().openSession();
    System.out.println("connection got");
    try{
    tx = session.beginTransaction();
    String q= "SELECT d.c1, d.c0, d.DevID, d.SensorType FROM SensorReadings d WHERE d.DevID= evID AND d.SensorType= :SensorType";
    Query query = session.createQuery(q);
    query.setParameter("DevID",x);
    query.setParameter("SensorType", y);
    System.out.println("query executed");
    for(Iterator it=query.iterate();it.hasNext(){
    Object[] ob = (Object[]) it.next();
    System.out.println("Coefficent 1 is :" + ob[0]);
    System.out.println("Coefficent 0 is :" + ob[1]);
    System.out.println("Device ID is : " + ob[2]);
    System.out.println("Sensor type is : " + ob[3]);
    c[1]= (String)ob[0]; // contains coeff 1 c1 here i am getting NULL POINTER EXCEPTION
    c[0]= (String)ob[1]; // contains coeff 0 c0
    tx.commit();
    }
    }catch(HibernateException e){
    System.out.println("Hibernate exception occured");
    e.printStackTrace();
    }catch(Exception d){
    System.out.println("exception occured");
    d.printStackTrace();
    }
    finally
    {
    session.close();
    }
    return c ;

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Null pointer exception in hibernate

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kirangk is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: Null pointer exception in hibernate

    it is solved sorry

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Null pointer exception in hibernate

    For future reference, please be forthright when posting the same question on multiple forums.

    Cross posted at [SOLVED] NULL POINTER EXCEPTION IN HIBERNATE

Similar Threads

  1. Null pointer exception?
    By coffee in forum New To Java
    Replies: 4
    Last Post: 08-03-2009, 03:22 AM
  2. null pointer exception
    By anthonym2121 in forum New To Java
    Replies: 7
    Last Post: 04-06-2009, 03:25 AM
  3. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 03:30 AM
  4. Null Pointer Exception
    By ScKaSx in forum New To Java
    Replies: 1
    Last Post: 01-24-2009, 11:27 AM
  5. Null Pointer Exception
    By Jacinth in forum New To Java
    Replies: 4
    Last Post: 01-22-2009, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •