wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes NULL POINTER EXCEPTION IN HIBERNATE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "NULL POINTER EXCEPTION IN HIBERNATE" Watch "NULL POINTER EXCEPTION IN HIBERNATE" New topic
Author

NULL POINTER EXCEPTION IN HIBERNATE

kiran gk
Greenhorn

Joined: May 09, 2012
Posts: 5
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 ;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NULL POINTER EXCEPTION IN HIBERNATE
 
Similar Threads
retreiving data through jsp
visual J++ and retreiving rows from sql server
Error Retreiving a resultset from an oracle stored procedure
Retreiving a image from a database using servlet
Polynomial LinkedList from Text File (Modification)