Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: NULL POINTER EXCEPTION IN HIBERNATE

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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
    Junior Member
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: NULL POINTER EXCEPTION IN HIBERNATE

    sorry it is solved

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: NULL POINTER EXCEPTION IN HIBERNATE

    This thread has been cross posted here:

    http://www.java-forums.org/hibernate/59685-null-pointer-exception-hibernate.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. [B]Null Pointer Exception[/B]-- Please Help!!!
    By entwicklerin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 24th, 2012, 11:24 AM
  2. Null Pointer Exception Help !!
    By AlterEgo1234 in forum Member Introductions
    Replies: 1
    Last Post: March 27th, 2011, 10:07 AM
  3. Null Pointer Exception Help!!
    By puzzledstudent in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 11th, 2010, 06:46 PM
  4. Null pointer exception
    By Wrathgarr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2010, 12:48 AM
  5. Null Pointer Exception
    By MysticDeath in forum Exceptions
    Replies: 2
    Last Post: October 24th, 2009, 01:49 PM