School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Exception in thread "main" java.lang.NullPointerException plz help me Rate Topic: -----

#1 brijesh25tripathi  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 09-February 09


Dream Kudos: 0

Share |

Exception in thread "main" java.lang.NullPointerException

Posted 09 February 2009 - 09:47 PM

hi every one....can any one help me out .....whenever i run this code i get the following error.....plz let me know what i m doing wrong....

ERROR:->
==============================================
0 [main] INFO TestClient - creating honey
31 [main] INFO net.sf.hibernate.cfg.Environment - Hibernate 2.1.8
31 [main] INFO net.sf.hibernate.cfg.Environment - hibernate.properties not found
47 [main] INFO net.sf.hibernate.cfg.Environment - using CGLIB reflection optimizer
47 [main] INFO net.sf.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
47 [main] INFO net.sf.hibernate.cfg.Configuration - configuring from resource: E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml
47 [main] INFO net.sf.hibernate.cfg.Configuration - Configuration resource: E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml
47 [main] WARN net.sf.hibernate.cfg.Configuration - E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml not found
%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.HibernateException: E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:886)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:910)
at de.laliluna.example.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
at de.laliluna.example.TestClient.createHoney(TestClient.java:42)
at de.laliluna.example.TestClient.main(TestClient.java:24)
Exception in thread "main" java.lang.NullPointerException
at de.laliluna.example.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:56)
at de.laliluna.example.TestClient.createHoney(TestClient.java:42)
at de.laliluna.example.TestClient.main(TestClient.java:24)
================================================

package de.laliluna.example;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.cfg.Configuration;

public class HibernateSessionFactory {
private static net.sf.hibernate.SessionFactory sessionFactory;


public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null || ! session.isConnected()) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}

return session;
}
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

if (session != null) {
session.close();
}
}
private HibernateSessionFactory() {
}

}


Was This Post Helpful? 0
  • +
  • -


#2 General Adamus  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 9
  • View blog
  • Posts: 110
  • Joined: 05-February 09


Dream Kudos: 0

Re: Exception in thread "main" java.lang.NullPointerException

Posted 10 February 2009 - 12:10 PM

E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml not found

1. Your main drive is E?
2. You're using an xml file and not .mdf?
3. The xml reader might not like the double extension .cfg.xml

Hope that helps,

Adamus

...and personally, I would always use a UNC path in place of the windows directory path for all references to files.

i.e. //192.168.32.1/e$/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.xml

...and I would remove the .cfg or concatenate to the file name: hibernateconfig.xml

Adamus

This post has been edited by General Adamus: 10 February 2009 - 12:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 brijesh25tripathi  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 09-February 09


Dream Kudos: 0

Re: Exception in thread "main" java.lang.NullPointerException

Posted 10 February 2009 - 11:23 PM

View PostGeneral Adamus, on 10 Feb, 2009 - 12:10 PM, said:

E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml not found

1. Your main drive is E?
2. You're using an xml file and not .mdf?
3. The xml reader might not like the double extension .cfg.xml

Hope that helps,

Adamus

...and personally, I would always use a UNC path in place of the windows directory path for all references to files.

i.e. //192.168.32.1/e$/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.xml

...and I would remove the .cfg or concatenate to the file name: hibernateconfig.xml

Adamus







hi...thanks for ur reply.....ya E: is my main drive...and i m using XML.....
as u said i changed all those things but still getting same error....so please tell me some thing more so i can check it out.....
thanks
Was This Post Helpful? 0
  • +
  • -

#4 General Adamus  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 9
  • View blog
  • Posts: 110
  • Joined: 05-February 09


Dream Kudos: 0

Re: Exception in thread "main" java.lang.NullPointerException

Posted 11 February 2009 - 05:10 AM

View Postbrijesh25tripathi, on 10 Feb, 2009 - 11:23 PM, said:

View PostGeneral Adamus, on 10 Feb, 2009 - 12:10 PM, said:

E:Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.cfg.xml not found

1. Your main drive is E?
2. You're using an xml file and not .mdf?
3. The xml reader might not like the double extension .cfg.xml

Hope that helps,

Adamus

...and personally, I would always use a UNC path in place of the windows directory path for all references to files.

i.e. //192.168.32.1/e$/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/JOBS/hibernate.xml

...and I would remove the .cfg or concatenate to the file name: hibernateconfig.xml

Adamus







hi...thanks for ur reply.....ya E: is my main drive...and i m using XML.....
as u said i changed all those things but still getting same error....so please tell me some thing more so i can check it out.....
thanks

Unfortunately, I haven't touched Java since college more than 10 years ago, but the error you're receiving can't find your xml file. I would copy the directory and paste it into windows explorer to see if it resolves.

Also, I would consider a permissions issue expecially if you're using Vista. Try reading the xml from your desktop or MyDocuments.

Adamus
Was This Post Helpful? 0
  • +
  • -

#5 brijesh25tripathi  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 09-February 09


Dream Kudos: 0

Re: Exception in thread "main" java.lang.NullPointerException

Posted 11 February 2009 - 08:40 PM

hi...i had resolved that problem...but now i m getting some other error....please see and tell me where its goes wrong......thanks

Error:-
------------------------------------------------------------------------------------
Feb 12, 2009 10:05:56 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.3.1.GA
Feb 12, 2009 10:05:56 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Feb 12, 2009 10:05:56 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Feb 12, 2009 10:05:56 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Feb 12, 2009 10:05:57 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Feb 12, 2009 10:05:57 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Feb 12, 2009 10:05:57 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : contact.hbm.xml
Feb 12, 2009 10:05:57 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: roseindia.tutorial.hibernate.Contact -> CONTACT
Feb 12, 2009 10:05:58 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: roseindia.tutorial.hibernate.Book -> book
Feb 12, 2009 10:05:58 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: roseindia.tutorial.hibernate.Insurance -> insurance
Feb 12, 2009 10:05:58 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:28)
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users