Exception in thread "main" java.lang.NullPointerException
hi
I am new to Java, and taking an introductory course in java. I wrote the code given bellow and get following error "C:\java\assingment2>java test123
Exception in thread "main" java.lang.NullPointerException
at PartCatalog.Add(test123.java:56)
at test123.main(test123.java:102)"
Can any body help me please
import java.util.*;
class PartRecord
public String PartName;
public String PartNumber;
public float Cost;
public int Quantity;
public static int counter ;
public PartRecord()
{ PartName ="";
PartNumber="";
Cost = 0;
Quantity = 0;
counter = 0;
public void Set(String name, final String num,
float cost, int quantity)
PartName = name;
PartNumber= num;
Cost = cost;
Quantity = quantity;
counter++;
public float Get()
return Cost*Quantity;
public static int Counter() {return counter;}
class PartCatalog
public PartCatalog()
npart=0;
public void Add(String name, String num,
float cost, int quantity)
if(npart>=1000) return;
Parts[npart++].Set(name,num,cost,quantity);
public float ShowInventory()
int inventory = 0;
for(int i=0; i<npart; i++)
inventory+= Parts.Get();
return inventory;
public PartRecord[] Parts = new PartRecord[1000];
public int npart;
class ExtPartCatalog extends PartCatalog
public void Sort()
Arrays.sort(Parts);
public void Print()
for(int i=0; i<npart; i++)
System.out.println ( Parts[i].PartName + "\t "
+ Parts[i].PartNumber + "\t "
+ Parts[i].Cost + "\t "
+ Parts[i].Quantity + "\n");
class test123{
public static void main(String args[])
ExtPartCatalog catalog = new ExtPartCatalog();
catalog.Add("tire ", "1", 45, 200);
catalog.Add("microwave", "2", 95, 10);
catalog.Add("CD Player", "3", 215, 11);
catalog.Add("Chair ", "4", 65, 10);
catalog.Sort();
catalog.Print();
System.out.println("Inventory is " + catalog.ShowInventory());
ExtPartCatalog catalog2 = new ExtPartCatalog();
catalog2.Add("ttt ", "1", 45, 200);
System.out.print("\n\nTotally there are " + PartRecord.Counter() );
System.out.println(" Parts being set" );
Thank you for your reply. I think i used
public PartRecord[] Parts = new PartRecord[1000];
so i have created the reference. I tries what you told me but it still did not work. I am putting the code again, but now in the formatted form so that you can read it more easily. I will appreciate your help. Thanks
<code>
import java.util.*;
class PartRecord
{ public String PartName;
public String PartNumber;
public float Cost;
public int Quantity;
public static int counter ;
public PartRecord()
PartName ="";
PartNumber="";
Cost = 0;
Quantity = 0;
//counter = 0;
public void Set(String name, final String num,
float cost, int quantity)
PartName = name;
PartNumber= num;
Cost = cost;
Quantity = quantity;
counter++;
public float Get()
return Cost*Quantity;
public static int Counter() {return counter;}
class PartCatalog
{ public PartRecord[] Parts = new PartRecord[1000];
public int npart;
public PartCatalog()
npart=0;
public void Add(String name, String num,
float cost, int quantity)
if(npart>=1000) return;
Parts[npart++].Set(name,num,cost,quantity);
public float ShowInventory()
float inventory = 0;
for(int i=0; i<npart; i++)
inventory= Parts[npart].Get();
return inventory;
/*class ExtPartCatalog extends PartCatalog
public void Sort()
Arrays.sort(Parts);
public void Print()
for(int i=0; i<npart; i++)
System.out.println ( Parts.PartName + "\t "
+ Parts[i].PartNumber + "\t "
+ Parts[i].Cost + "\t "
+ Parts[i].Quantity + "\n");
class azimi_a{
public static void main(String args[])
PartCatalog c = new PartCatalog() ;//= new PartCatalog[4];
c.Add("tire ", "1", 45, 200);
c.Add("microwave", "2", 95, 10);
c.Add("CD Player", "3", 215, 11);
c.Add("Chair ", "4", 65, 10);
<code>
Similar Messages
-
Problem about "Exception in thread "main" java.lang.NullPointerException"
This is t error message once i run the file
Exception in thread "main" java.lang.NullPointerException
at sendInterface.<init>(sendInterface.java:64)
at sendInterface.main(sendInterface.java:133)
* @(#)sendInterface.java
* @author
* @version 1.00 2008/7/18
import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.UIManager;
import javax.swing.SwingConstants;
import java.io.*;
import java.sql.*;
import java.net.*;
public class sendInterface /*implements ActionListener*/{
JFrame frame = new JFrame();
private Panel topPanel;
private Panel sendMessagePanel;
private Panel sendFilePanel;
private JLabel senderID;
private JLabel receiverID;
private JLabel senderDisplay;
private DefaultListModel receiverListModel = new DefaultListModel();
private JList receiverID_lst = new JList(receiverListModel);
private JRadioButton sendType;
String userName;
String[] userList = null ;
int i=0;
Connection con;
public sendInterface() {
String ListName;
try
JFrame.setDefaultLookAndFeelDecorated( true );
catch (Exception e)
System.err.println( "Look and feel not set." );
frame.setTitle( "Send Interface" );
topPanel.setLayout( new GridLayout( 2 , 1 ) ); //line 64*************************
senderID = new JLabel( "Sender:", SwingConstants.LEFT );
senderDisplay = new JLabel( "'+...+'", SwingConstants.LEFT );
receiverID = new JLabel( "Receiver:", SwingConstants.LEFT);
// receiverID_lst = new JList( ListName );
frame.add(senderID);
frame.add(senderDisplay);
frame.add(receiverID);
// frame.add(receiverListModel);
frame.add(new JScrollPane(receiverID_lst), BorderLayout.CENTER);
frame.setLocation(200, 200);
frame.setSize(250, 90);
frame.setVisible(true);
public void setListName(String user)
try{
userName = user;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/thesis";
con = DriverManager.getConnection(url, "root", "");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select * from user where User_ID!= '" + userName + "'");
System.out.println("Display all results:");
while(rs.next()){
String user_id = rs.getString("User_ID");
System.out.println("\tuser_id= " + user_id );
// receiverListModel.addElement(user_id);
userList=user_id;
i++;
}//end while loop
receiverListModel.addElement(userList);
catch(Exception ex)
ex.printStackTrace();
finally
if (con != null)
try
con.close ();
System.out.println ("Database connection terminated");
catch (Exception e) { /* ignore close errors */ }
public String getUserName()
return userName;
public String[] getUserList()
return userList;
public static void main(String[] args) {
new sendInterface(); //line 133******************************************
thank ur reply:D
Edited by: ocibala on Aug 3, 2008 9:54 AMAnd where do you instantiate topPanel before you invoke setLayout?
db -
Help with Exception in thread "main" java.lang.NullPointerException
I got this exception while running the code in Netbeans IDE 6.1. The code is compiling fine...Please tell me what the problem is
Exception in thread "main" java.lang.NullPointerException
at Softwareguide.chooseanswer(Softwareguide.java:32)
at Driver.main(Driver.java:7)
public class Driver
public static void main(String[] args)
Softwareguide swguide = new Softwareguide();
swguide.chooseanswer();
public class Softwareguide
State test1;
State test2;
State test3;
State test4;
State test5;
State subtest1;
State subtest2;
State subtest3;
State subtest4;
State subtest5;
State state = test1;
public Softwareguide()
test1 = new Test1(this);
test2 = new Test2(this);
test3 = new Test3(this);
test4 = new Test4(this);
test5 = new Test5(this);
subtest1 = new SubTest1(this);
subtest2 = new SubTest2(this);
subtest3 = new SubTest3(this);
subtest4 = new SubTest4(this);
subtest5 = new SubTest5(this);
public void chooseanswer()
state.chooseanswer();
/* public void chooseyes()
state.chooseyes();
public void chooseno()
state.chooseno();
public State getState()
return state;
void setState(State state)
this.state = state;
public State getTest1State()
return test1;
public State getTest2State()
return test2;
public State getTest3State()
return test3;
public State getTest4State()
return test4;
public State getTest5State()
return test5;
public State getsubTest1State()
return subtest1;
public State getsubTest2State()
return subtest2;
public State getsubTest3State()
return subtest3;
public State getsubTest4State()
return subtest4;
public State getsubTest5State()
return subtest5;
public String toString()
StringBuffer result = new StringBuffer();
result.append("\n Starting Diagnostic Test...");
return result.toString();
}spiderjava wrote:
the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
You should definitly not write a technical Java blog and post it all over the place. -
Exception in thread "main" java.lang.NullPointerException error JDeveloper 12c
Hello,
I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
I have a table "Beer" and I want to select all the data out with a stored procedure which I call out of Java app.
I have a java.class file Store_A.java which I have loaded into the ORACLE database with LOADJAVA :
import java.sql.*;
import java.io.*;
public class Store_a {
public static void apskatit ()
throws SQLException
{ String sql =
"SELECT * FROM Beer";
try { Connection conn = DriverManager.getConnection("jdbc:default:connection:");
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rset = pstmt.executeQuery();
rset.close();
pstmt.close();
catch (SQLException e) {System.err.println(e.getMessage());
Then I have created a procedure which I plan to call out in java:
CREATE OR REPLACE PACKAGE Store_a AS
PROCEDURE apskatit;
END Store_a;
CREATE OR REPLACE PACKAGE BODY Store_a AS
PROCEDURE apskatit AS LANGUAGE JAVA
NAME 'Store_a.apskatit()';
END Store_a;
And I have a java file that I have created with JDeveloper 12c:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Class1 {
* @param args
public static void main(String[] args) throws SQLException {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//Izveidojam savienojumu
conn = DriverManager.getConnection("jdbc.oracle.thin:@localhost:1521", "SYSTEM", "asdasd");
// Izveidojam callable statement
CallableStatement stmt = conn.prepareCall("CALL Store_a.apskatit()");
ResultSet resul = stmt.executeQuery();
while (resul.next()) {
System.out.println(resul.getInt(1) + "\t" + resul.getString(2));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
When I try to run the java file, I get this error "Exception in thread "main" java.lang.NullPointerException at client.Class1.main(Class1.java:29).
So the line I get error in is "conn.close();"
How to fix this?
Thank you very much in advance.I am trying to call a java stored procedure in java application. I am using ORACLE database and JDeveloper.
I am getting error "Exception in thread "main" java.lang.NullPointerException. I have no idea what have I been doing wrong.
Maybe you haven't read it yet but I told you in your other thread what you were doing wrong and, step by step, how to address the problem.
https://forums.oracle.com/thread/2611124
I'm not going to repeat everything again just this one main piece of advice:
Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
You are trying to deal with too many different issues at the same time. Unless you solve your primary Java problem by fixing the code outside the DB you will have nothing but problems loading it into the DB.
And just get rid of this line of code - you don't need it anymore and it hasn't been done like that for many years now:
Class.forName("oracle.jdbc.driver.OracleDriver"); -
Exception in thread "main" java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration
at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:963)
at javax.media.j3d.Canvas3D.<init>(Canvas3D.java:1006)
at HelloJava3Da.<init>(HelloJava3Da.java:16)
at HelloJava3Da.main(HelloJava3Da.java:45)Hello, Can you paste your code here?
I think you may miss the following
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);Thanks & Regards
<~ChaosCrisis~> -
Re: Exception in thread "main" java.lang.NullPointerException
Hi
I am getting the following error. I cannot see any uninitialised objects. I have spent enough time on it .Could someone help me with this.
Thanks in advance
Exception in thread "main" java.lang.NullPointerException
at pointlist.pointList.add(pointList.java:31)
at pointlist.pointList.main(pointList.java:67)
at pointlist.pointList.add(pointList.java:31)
at pointlist.pointList.main(pointList.java:67)
package pointlist;
import javax.vecmath.Point2d;
public class pointList extends Point2d{
protected transient int size = 0;
protected Point2d[] pointList = new Point2d[10];
public pointList(){
public void add(int x,int y){
if(pointList.length == size)
resize(pointList.length * 2);
System.out.print(size+"\n");
pointList[size].setX(x);
pointList[size].setY(y);
System.out.print(x+"\n"+y);
size++;
System.out.print("\n"+size);
public int size(){
if(size <= 0)
return(0);
else
return(size-1);
private void resize(int newsize){
Point2d[] newpointList = new Point2d[newsize]; // Create a new array
public int[] get(int index){
if(index>size)
throw new ArrayIndexOutOfBoundsException(index);
else
int[] point = new int[2];
point[0] = (int)pointList[index-1].x;
point[1] = (int)pointList[index-1].y;
return(point);
public static void main(String args[]){
pointList plist = new pointList();
plist.add(10, 10);
}An Object-array (or in your case an array of Point2D) is just an array of references in Java.
With "new Point2D[10]" you've created an array capable of holding 10 references to Point2D objects, but you've not yet created an Point2D object (each of those references is null). You'll need to create such a Point2D object in your add() method (before you try to call setX() and setY() on it).
Two additional hints:
* Your class should really be called PointList, because class names should start with a upper-case letter in Java
* your resize method doesn't keep the old values, but simply creates a new (empty) array. -
Need help with Exception in thread "main" java.lang.NullPointerException
here is the error
Exception in thread "main" java.lang.NullPointerException
at stream.createFrame(stream.java:153)
at chat.createMessage(chat.java:14)
this is where the error is in stream
public void createFrame(int id) {
*buffer[currentOffset++] = (byte)(id + packetEncryption.getNextKey());*
and this is where it comes from in chat
outStream.createFrame(85);
i just cant see whats causeing the exceptionspiderjava wrote:
the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
You should definitly not write a technical Java blog and post it all over the place. -
Help with arrays and Exception in thread "main" java.lang.NullPointerExcept
Hi, I have been having trouble all day getting this array sorted and put into a new array. I think it is something simple with my nested loops in sortCityArray() that is causing the problem. Any help would be greatly appreciated. The error is thrown on line 99 at Highway.sortCityArray(Highway.java:99)
import java.util.Scanner;
import java.io.*;
import java.util.Arrays;
public class Highway
private String[] listOfCities=new String[200];
private City[] cityArray=new City[200];
private City[] sortedCityArray=new City[200];
private String city="";
private String city2="";
private String fileName;
private City x;
private int milesToNextCity;
private int milesAroundNextCity;
private int speedToNextCity;
public Highway(String filename)
String fileName=filename;//"I-40cities.txt";
File myFile = new File(fileName);
try {
Scanner scan=new Scanner(myFile);
for(int i=0; scan.hasNextLine(); i++){
String city=scan.nextLine();
String city2=scan.nextLine();
int milesToNextCity=scan.nextInt();
int milesAroundNextCity=scan.nextInt();
int speedToNextCity=scan.nextInt();
if(scan.hasNextLine()){
scan.nextLine();
cityArray=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
// System.out.println(cityArray[i].getCity());
// System.out.println(cityArray[i].getNextCity());
// System.out.println(cityArray[i].getLengthAB());
// System.out.println(cityArray[i].getLengthAroundB());
// System.out.println(cityArray[i].getSpeedAB());
catch (Exception e) {
System.out.println(e);
//return cityArray;
/*public City[] doCityArray(){
File myFile = new File(fileName);
try {
Scanner scan=new Scanner(myFile);
for(int i=0; scan.hasNextLine(); i++){
String city=scan.nextLine();
String city2=scan.nextLine();
int milesToNextCity=scan.nextInt();
int milesAroundNextCity=scan.nextInt();
int speedToNextCity=scan.nextInt();
if(scan.hasNextLine()){
scan.nextLine();
cityArray[i]=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
// System.out.println(cityArray[i].getCity());
// System.out.println(cityArray[i].getNextCity());
// System.out.println(cityArray[i].getLengthAB());
// System.out.println(cityArray[i].getLengthAroundB());
// System.out.println(cityArray[i].getSpeedAB());
catch (Exception e) {
System.out.println(e);
return cityArray;
public City[] sortCityArray(){
sortedCityArray[0]=new City(cityArray[0].getCity(),cityArray[0].getNextCity(),cityArray[0].getLengthAB(),cityArray[0].getLengthAroundB(),cityArray[0].getSpeedAB());
for(int j=0; j<cityArray.length; j++ )
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
/* for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
// j++;
System.out.println(sortedCityArray[0].getCity());
System.out.println(sortedCityArray[0].getNextCity());
System.out.println(sortedCityArray[0].getLengthAB());
System.out.println(sortedCityArray[0].getLengthAroundB());
System.out.println(sortedCityArray[0].getSpeedAB());
System.out.println(sortedCityArray[1].getCity());
System.out.println(sortedCityArray[1].getNextCity());
System.out.println(sortedCityArray[1].getLengthAB());
System.out.println(sortedCityArray[1].getLengthAroundB());
System.out.println(sortedCityArray[1].getSpeedAB());
System.out.println(sortedCityArray[2].getCity());
System.out.println(sortedCityArray[2].getNextCity());
System.out.println(sortedCityArray[2].getLengthAB());
System.out.println(sortedCityArray[2].getLengthAroundB());
System.out.println(sortedCityArray[2].getSpeedAB());
System.out.println(sortedCityArray[3].getCity());
System.out.println(sortedCityArray[3].getNextCity());
System.out.println(sortedCityArray[3].getLengthAB());
System.out.println(sortedCityArray[3].getLengthAroundB());
System.out.println(sortedCityArray[3].getSpeedAB());
System.out.println(sortedCityArray[4].getCity());
System.out.println(sortedCityArray[4].getNextCity());
System.out.println(sortedCityArray[4].getLengthAB());
System.out.println(sortedCityArray[4].getLengthAroundB());
System.out.println(sortedCityArray[4].getSpeedAB());
return cityArray;
/*public String[] listOfCities(){
File myFile = new File("I-40cities.txt");
try {
Scanner scan=new Scanner(myFile);
for(int i=0; scan.hasNextLine(); i++){
String city=scan.nextLine();
city=city.trim();
scan.nextLine();
scan.nextLine();
listOfCities[i]=city;
System.out.println(listOfCities[i]);
catch (Exception e) {
System.out.println(e);
return listOfCities;
public static void main(String args[]) {
Highway h = new Highway("out-of-order.txt");
h.sortCityArray();the ouput is perfect according to the print lines if I use (increase the int where j is in the loop manually by one) :
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[0].getNextCity().equals(cityArray.getCity())){
sortedCityArray[0+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[1].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[1+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[2].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[2+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
for(int i=0; i<cityArray.length ;i++)
if(sortedCityArray[3].getNextCity().equals(cityArray[i].getCity())){
sortedCityArray[3+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
break;
But I cant do this for 200 elements. Are the loops nested right?
Edited by: modplan on Sep 22, 2008 6:49 PM -
Exception in thread "main" java.lang.ExceptionInInitializerError
Exception in thread "main" java.lang.ExceptionInInitializerError
at platinum.logger.XAbstractLogger.setStreams(XAbstractLogger.java:44)
at platinum.logger.XConsoleLogger.initStreams(XConsoleLogger.java:32)
at platinum.logger.XConsoleLogger.<init>(XConsoleLogger.java:27)
at platinum.platinum.main(platinum.java:55)
Caused by: java.lang.NullPointerException
at platinum.util.XResourceManager.initResourceBundle(XResourceManager.java:34)
at platinum.XRepository.<clinit>(XRepository.java:109)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I get a msg like this wen i try to run my project.
The code which gives the error is:
import java.io.*;
import java.util.*;
import platinum.*;
public abstract class XAbstractLogger implements XLogger
public XAbstractLogger()
this(XProjectConstants.LOG_MODE_VERBOSE);
public XAbstractLogger(int log_mode)
setLogMode( new XLogMode(log_mode) );
protected void setStreams(PrintStream ps_out, PrintStream ps_err) throws IOException,Exception
out = ps_out;
err = ps_err;
// Log some stuff
String[] props = {
"java.version", "java.vendor", "java.compiler", "os.name",
"os.version", "os.arch", "user.home"
if( !logMode.isOff() )
logImpl(XRepository.getLogger(), "When reporting bugs, please include the following information:", MESSAGE, out);
logImpl(XRepository.getLogger(), XProjectConstants.PRODUCT_NAME+" version="+XProjectConstants.PRODUCT_VERSION, MESSAGE, out);
for( int i=0; i<props.length; i++)
logImpl(XRepository.getLogger(), props[i] + "=" + System.getProperty(props), MESSAGE, out);
public void setLogMode(XLogMode log_mode)
logMode = log_mode;
public void addLogException(String log_e, XLogMode log_mode)
if( !logExceptions_Modes.containsKey(log_e) )
logExceptions_Modes.put(log_e, log_mode);
public void removeLogException(String log_e)
logExceptions_Modes.remove(log_e);
public final void message(Object src, Object obj)
if( logMode.getLogMessages() )
logImpl(src, obj, MESSAGE, out);
public final void debug(Object src, Object obj)
if( logMode.getLogDebugs() )
logImpl(src, obj, DEBUG, out);
public final void warning(Object src, Object obj)
if( logMode.getLogWarnings() )
logImpl(src, obj, WARNING, err);
public final void error(Object src, Object obj)
if( logMode.getLogErrors() )
logImpl(src, obj, ERROR, err);
private void logImpl(Object src, Object obj, int type, PrintStream ps)
if( ps==null )
return;
String class_name = XRepository.getResourceManager().getClassName(src);
if( isAnException(class_name, type) )
return;
ps.print("["+getTitle(type)+"-"+class_name+"] ");
if( obj instanceof Throwable )
((Throwable)obj).printStackTrace(ps);
else
ps.println(obj);
private boolean isAnException(String str, int type)
Iterator it = logExceptions_Modes.keySet().iterator();
String excep_item;
XLogMode log_mode;
while( it.hasNext() )
excep_item = (String)it.next();
log_mode = (XLogMode)logExceptions_Modes.get(excep_item);
if( excep_item.equalsIgnoreCase(str) )
if( ((type==MESSAGE) && (log_mode.getLogMessages()==false)) ||
((type==DEBUG) && (log_mode.getLogDebugs()==false)) ||
((type==WARNING) && (log_mode.getLogWarnings()==false)) ||
((type==ERROR) && (log_mode.getLogErrors()==false)) )
return true;
return false;
private String getTitle(int type)
switch( type )
case MESSAGE:
return ">Message:";
case DEBUG:
return ">Debug:";
case WARNING:
return ">Warning:";
case ERROR:
return ">Error:";
default:
return ">??!!";
// Attributes:
private static final int MESSAGE = 1;
private static final int DEBUG = 3;
private static final int WARNING = 5;
private static final int ERROR = 7;
private PrintStream out = null;
private PrintStream err = null;
private Map logExceptions_Modes = new HashMap();
private XLogMode logMode = new XLogMode();The code which gives the error is:You have read the stack trace incorrectly and posted the wrong code.... read the trace again:
at platinum.platinum.main(platinum.java:55)
Caused by: java.lang.NullPointerException
at platinum.util.XResourceManager.initResourceBundle(XResourceManager.java:34)
at platinum.XRepository.<clinit>(XRepository.java:109) Something is throwing null pointer exception in *'platinum.util.XResourceManager.initResourceBundle'* method.
Thanks! -
Exception in thread "main" java.lang
hi,
I have java app which is called cutter.jar , I wanna run it using run.bat file which contain this line:
java -classpath .;cutter.jar Cutter
when I run --> run.bat I get this error message:
java -classpath cutter.jar Cutter
Exception in thread "main" java.lang.ExceptionInInitializerError
at Cutter.main(Cutter.java:96)
Caused by: java.lang.NullPointerException
at Preferences.<clinit>(Preferences.java:995)
... 1 more
Please help ASAP, I'm not the Java user but must use this cutter app.
ThanksPost each question only once.
http://forum.java.sun.com/thread.jspa?threadID=5140780
http://forum.java.sun.com/thread.jspa?threadID=5140779 -
Exception in thread "main" java.lang.NoClassDefFoundError
Am using java 1.3.1 on Red Hat Linux 7.1
i get this error
Exception in thread "main" java.lang.NoClassDefFoundError
while running a simple program HelloWorld.java
helpWhen you use the "java" command, the only required argument is the name of the class that you want to execute. This argument must be a class name, not a file name, and class names are case sensitive. For example, "java HelloWorld.java" won't work because the class name isn't HelloWorld.java, it's HelloWorld. Similarly, "java helloworld" won't work because a class defined as "public class HelloWorld {" is not named helloworld due to case sensitivity. Finally, the .class file must be in a directory that is in the Classpath - that's where java.exe searches to find the file that contains the class.
-
HELP Needed with this error: Exception in thread "main" java.lang.NoClass
Folks,
I am having a problem connecting to my MSDE SQL 2000 DB on a WindowsXP pro. environment. I am learning Java and writing a small test prgm to connect the the database. The code compiles ok, but when I try to execute it i keep getting this error:
"Exception in thread "main" java.lang.NoClassDefFoundError: Test1"
I am using the Microsoft jdbc driver and my CLASSPATH is setup correctly, I've also noticed that several people have complained about this error, but have not seen any solutions....can someone help ?
Here is the one of the test programs that I am using:
import java.sql.*;
* Microsoft SQL Server JDBC test program
public class Test1 {
public Test1() throws Exception {
// Get connection
DriverManager.registerDriver(new
com.microsoft.jdbc.sqlserver.SQLServerDriver());
Connection connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://LAPTOP01:1433","sa","sqladmin");
if (connection != null) {
System.out.println();
System.out.println("Successfully connected");
System.out.println();
// Meta data
DatabaseMetaData meta = connection.getMetaData();
System.out.println("\nDriver Information");
System.out.println("Driver Name: "
+ meta.getDriverName());
System.out.println("Driver Version: "
+ meta.getDriverVersion());
System.out.println("\nDatabase Information ");
System.out.println("Database Name: "
+ meta.getDatabaseProductName());
System.out.println("Database Version: "+
meta.getDatabaseProductVersion());
} // Test
public static void main (String args[]) throws Exception {
Test1 test = new Test1();I want to say that there was nothing wrong
with my classpath config., I am still not sure why
that didn't work, there is what I did to resolved
this issue.You can say that all you like but if you are getting NoClassDefFound errors, that's because the class associated with the error is not in your classpath.
(For future reference: you will find it easier to solve problems if you assume that the problem is your fault, instead of trying to blame something else. It almost always is your fault -- at least that's been my experience.)
1. I had to set my DB connection protocol to TCP/IP
(this was not the default), this was done by running
the
file "svrnetcn.exe" and then in the SQL Server Network
Utility window, enable TCP/IP and set the port to
1433.Irrelevant to the classpath problem.
2. I then copied all three of the Microsoft JDBC
driver files to the ..\jre\lib\ext dir of my jdk
installed dir.The classpath always includes all jar files in this directory. That's why doing that fixed your problem. My bet is that you didn't have the jar file containing the driver in your classpath before, you just had the directory containing that jar file.
3. Updated my OS path to located these files
and....BINGO! (that simple)Unnecessary for solving classpath problems.
4. Took a crash course on JDBC & basic Java and now I
have created my database, all tables, scripts,
stored procedures and can read/write and do all kinds
of neat stuff.All's well that ends well. After a few months you'll wonder what all the fuss was about. -
Hi
I am trying to use type 4 driver to connect to my Oracle 9i Rel2 database. I downloaded the odbc14.jar from oracle and added in the C:\Oracle9i\jdbc\lib path. As on the website, I setup my environment:
Setting Up Your Environment
On Win95/Win98/NT:
- Add [ORACLE_HOME]\jdbc\lib\classes111.zip and
[ORACLE_HOME]\jdbc\lib\nls_charset11.zip to your CLASSPATH.
(Add classes12.zip and nls_charset12.zip if JDK 1.2.x or 1.3 is
used. Add ojdbc14.jar and nls_charset12.zip if JDK 1.4 is used.)
- Make sure [ORACLE_HOME]\bin is in your PATH.
Still I am getting the following error during runtime:
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at jdbc.InsertQueryEx.main(InsertQueryEx.java:11)
Below is the source code:
import java.sql.*;
import java.io.*;
public class InsertQueryEx {
public static void main(String[] args)throws Exception{
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@Prashy:1521:orcl", "scott", "tiger");
DataInputStream din = new DataInputStream(System.in);
Statement stmt = con.createStatement();
while(true){
try{
System.out.println("enter emp name");
String name = din.readLine();
System.out.println("enter emp no");
int no = Integer.parseInt(din.readLine());
System.out.println("enter emp salary");
float sal = Float.parseFloat(din.readLine());
System.out.println("enter emp address");
String addr = din.readLine();
int count = stmt.executeUpdate("insert into myemp values("+no+",'"+name+"',"+sal+",'"+addr+"')");
if(count>0)
System.out.println("Record added");
else
System.out.println("Failed");
catch (Exception e){
System.err.println("Exception: "+e.getMessage());
Any help is appreciated
Thanks
PrashantI am sorry but I did add those in the classpath but still getting this error:
This is what I have for user variable in classpath:
.;C:\Oracle9i\jdbc\lib\ojdbc14.jar;C:\Oracle9i\jdbc\lib\nls_charset12.jar
error is:
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at jdbc.InsertQueryEx.main(InsertQueryEx.java:14)
Thanks -
DB:11.1.0.7
Oracle Apps:12.1.1
OS:RHEL Linux 4 86x64
Hi All,
On executing the following command on node 2 of TEST instance, we received the following error but did not find any such error messages in node 1
Notes: (1) Node 1 has java version:
java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
(2) Node 2 has java version:
java -version
java version "1.4.2"
gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-9)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Error message in node2:
On executing the following command on node 2 of TEST instance, we received the following error:
java oracle.jrad.tools.xml.importer.XMLImporter /tmp/custdocs/oracle/apps/pos/home/webui/customizations/site/0/PosHpgOrders.xml ....
/usr/bin/java: line 36: [: `)' expected, found -
Exception in thread "main" java.lang.VerifyError: verification failed at PC 152 in oracle.jdbc.driver.OracleDriver:registerMBeans(()V): String, int, or float constant expected
at JvBytecodeVerifier.verify_fail(byte, int) (/usr/lib64/libgcj.so.5.0.0)
at JvBytecodeVerifier.verify_instructions_0() (/usr/lib64/libgcj.so.5.0.0)
at JvVerifyMethod(_Jv_InterpMethod) (/usr/lib64/libgcj.so.5.0.0)
at JvPrepareClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at JvWaitForState(java.lang.Class, int) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at oracle.adf.mds.tools.util.ConnectUtils.getDBConnection(java.lang.String) (Unknown Source)
at oracle.jrad.tools.xml.importer.XMLImporter.importDocuments(java.lang.String[], java.sql.Connection) (Unknown Source)
at oracle.jrad.tools.xml.importer.XMLImporter.main(java.lang.String[]) (Unknown Source)
Could anyone please share such an issue faced before and provide resolution as to what's wrong in here in node 2?
Thanks for your time!
Regards,Hi,
(2) Node 2 has java version:
java -version
java version "1.4.2"Do you run this command as applmgr user? If yes, did you source the application env file?
Could anyone please share such an issue faced before and provide resolution as to what's wrong in here in node 2?Why the java version is different on the both nodes?
Thanks,
Hussein -
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
hi to all.
iam getting this error: could any one give me the solution.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at DinosaursDataLoader.getData(DinosaursDataLoader.java:49)
at DinosaursPack.load(DinosaursPack.java:22)
at DinosaursPack.<init>(DinosaursPack.java:18)
at myproject.main(myproject.java:17)
import java.util.*;
import java.io.*;
import javax.swing.ImageIcon;
public class Driver {
public static void main (String[] args) {
// create a Scanner and grab the data . . .
File f=new File("C:\\Users\\hariprasad koineni\\Desktop\\r.txt");// my text file containes 12 dinosuor card info
Scanner scanner = null;
try {
scanner = new Scanner(f);
} catch (FileNotFoundException fnf) {
System.out.println(fnf.getMessage());
System.exit(0);
// scan file line-by-line
scanner.useDelimiter("------------------------------------------------------------------");
int y=0;
while (scanner.hasNext()) {
String line = scanner.next().trim();
System.out.println(line);
String bits[]= new String[19];
String[] bit = line.split("\n"); // Regex available since Java 5
for(int j=0;j<=(bit.length-1);j++){
String[] bis = bit[j].split(":");
System.out.println(bis[0]);
String t=bis[1].trim();
bits[j]=t;
System.out.println(bits[j]);
System.out.println(j);
String t = bits[0]; // title
String imgFileName = bits[1]; // image file name
float h = Float.parseFloat(bits[2]); // height
String w = bits[3]; // weight
String l = bits[4]; // length
int kr = Integer.parseInt(bits[5]); // killer rating
String i = bits[6]; // intelligence
int a = Integer.parseInt(bits[7]); // age
String df = bits[8]; // dino file
// create the image
y++;
System.out.println(line);
System.out.println(y);
}h_koineni wrote:
sorry
iam getting the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Driver.main(Driver.java:38)So meaning this line cause the exception:
String t=bis[1].trim(); // hard-coded int literal 1That happens because, in line 36,
String[] bis = bit[j].split(":");What will happen if the delimiter ':' is not found? It will return an array with a size of 1, and at this time referencing index 1 is out of bound, remember that the upper bound of an array is its size-1. One workaround is to put a selection structure after line 36.
if (bis != null && bis.length == 2) {
String t=bis[1].trim();
bits[j]=t;
}Then, recompile your code and try again.
Maybe you are looking for
-
Basic functionality missing.
After the downtime yesterday, the speed has improved from completely unacceptable to marginally acceptable, but some basic functionality has disappeared. 1. Usually when more than one answer has been given in a thread, one would have the 'Go to origi
-
Since upgrading to OSX Lion (currently using iPhoto 11 9.1.5), iPhoto is not retaining, or 'holding' edits once editing mode has been left. In other words, if I go to edit, and crop (or touch-up, or adjust) a photo, as soon as I am NOT in editing mo
-
MKMapRectContainsPoint is failing on IOS 6
Hello, I am testing an application made for IOS 5 on IOS 6. I am using Mapkit and MKMapRectContainsPoint, it works on IOS 5 fine but it fails on IOS 6 for the same locations, so i made some tests and realize that the CGRect returned by visibleMapRect
-
I currently have a package and procedure created that I want to use. Yet when I run my script I am getting back an error. Here is the script: spool testlog.txt set pagesize 0 set linesize 2048 set heading off set feedback off set serveroutput off beg
-
HT4623 I cannot find the update section under Settings. What do I do?
I cannot find the update section under Settings. What do I do?