|
 |
pro_java_server thread: main" java.lang.NoClassDefFoundError??? NT/Oracle/jkd1.3
Message #1 by "frant turner" <seasundown@a...> on Sun, 29 Apr 2001 08:19:34
|
|
This may be a jdbc error stopping the entire
show.
I have some code from book : "Java2 for C/C++ progr
(Wiley)" which compiles & runs trees & other
graphical components mostly fine on my host.
However, the very two I need to see working
don't work ? 9 items are shown below:
compile errors for 2 files, classpath, dat file,
exectute error for 1 file, & source for the 4
related files. Straight off the web site &
book CD ( unedited).
Does anybody happen to have these up & running?
Wiley - Java2 & JavaScript for C/C++ progr.
http://www.cis.udel.edu/~vagrawal/367/examples/jwiley/chp21/
Or, is there recent code which is compatible with jdk1.3
which shows tree examples using jdbc / oracle?
I need to get these or other example working. Should
I consider installing an older verion ( jdk1.2 )?
Sad if true )?
--------------------------
I have jdk1.3 running & it works well
with other examples from books & web.
there must be a problem with this example
from book. Could it be this book ( probably
written before Java2 was actually out) had
code which is to old to work? I thought
this stuff was backward compatible.
------------------
TIA!!!
The 9 items follow (2 compile errors, 1 execute error, the
4 related code files, classpath, dat file to execute
( once these do compile) ...
---------------------------------------
compile errors from 2 files + execute error for 1
---------------------------------------
----------------------------------------------------------
javac TocFrame.java
TocFrame.java:33: cannot resolve symbol
symbol : class TocTreePanel
location: class jwiley.chp21.TocFrame
TocTreePanel tp = null;
^
TocFrame.java:36: cannot resolve symbol
symbol : class TocTreePanel
location: class jwiley.chp21.TocFrame
tp = new TocTreePanel(sTocFile);
^
2 errors
-------------------------------------------------
javac TestTableFrame.java
TestTableFrame.java:22: cannot resolve symbol
symbol : class DatabaseTableModel
location: class jwiley.chp21.TestTableFrame
DatabaseTableModel dataModel = null;
^
TestTableFrame.java:26: cannot resolve symbol
symbol : class DatabaseTableModel
location: class jwiley.chp21.TestTableFrame
new DatabaseTableModel("jdbc:odbc:ExampleDB",
-----------------------------------------------------------------
TocTreePanel.java compiles fine but won't run.
execution error for TocTreePanel (java TocTreePanel.java book.toc)
-----------------------------------------------------------------
java TocTreePanel book.toc
Exception in thread "main" java.lang.NoClassDefFoundError: TocTreePanel
(wrong name: jwiley/chp21/TocTreePanel)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass
(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
----------------------------------------------------------
"javac DatabaseTableModel.java" compiles fine, won't run, and is
mentioned ( above) in the compile error for TestTableFrame.java
----------------------------------------------------------
-----------------------------------------
My environment classpath:
-----------------------------------------
;d:\sybase-install\ASEP\3pclass.zip;d:\sybase-
install\ASEP\monclass.zip;.;c:\m
ysql\jdbc\twz1\noopt;c:\SDKs\Java\Sun\javacheck;c:\jdk1.3;c:\jdk1.3
\src.jar;c:
\jdk1.3\lib;c:\jdk1.3\lib\dt.jar;c:\jdk1.3\lib\tools.jar;c:\jdk1.3
\jre\lib;D:\
ORANT\orb\classes\yoj.jar;D:\ORANT\orb\classes\share.zip;d:\Ora3
\orb\classes\y
oj.jar;d:\Ora3\orb\classes\share.zip
-------------------------------------------------------
4 related code files ( the 1st TocTreePanel compiles fine)...
--------------------------------------------------------
/** TocTreePanel.java */
package jwiley.chp21;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Vector;
/**
* Class that generates a Tree from a heirarchically formatted text
* file.
* @author Michael C. Daconta
*/
public class TocTreePanel extends JPanel implements TreeSelectionListener
{
/** Debug variable. */
public static boolean debug;
/** Tree to generate. */
DefaultMutableTreeNode dynamicTree;
/** Graphical Tree Outline. */
JTree jt;
/** List Selection Model. */
TreeSelectionModel tsm;
/** Tree Model. */
TreeModel jtm;
/** Accessor. */
public DefaultMutableTreeNode getDynamicTree() { return dynamicTree; }
/** utility method to determine what level this node is at by
counting white space characters. The simplest way to format
the text file is to use one tab per level. */
private int countWhiteSpace(String sBuf)
{
for (int i=0; i < sBuf.length(); i++)
if (sBuf.charAt(i) != '\t' &&
sBuf.charAt(i) != ' ')
return i;
return -1; // error
}
/** Utility inner class to store both the position and a
reference to the DefaultMutableTreeNode at that position. */
class LevelNode
{
/** position of node. */
public int iPosition;
/** Tree node at that position. */
public DefaultMutableTreeNode node;
/** constructor. */
LevelNode(int iPos, DefaultMutableTreeNode t)
{ iPosition = iPos; node = t; }
}
/** Utility method to find the parent of the current node.
The algorithm is to start with the end of the Vector and
find out where this node "fits". A fit is when this
nodes position is greater than the previous one. */
private DefaultMutableTreeNode findParent(Vector levels, int nodePos)
{
int iLast = levels.size();
// start from the bottom
for (int i = (iLast - 1); i >= 0; i--)
{
LevelNode ln = (LevelNode) levels.elementAt(i);
if (nodePos > ln.iPosition)
return ln.node;
}
return null; // error
}
/** Utility method to parse a "Toc" file. File where each new
level is indicated by indenting that word. One word per line. */
private DefaultMutableTreeNode parseTableOfContents(FileInputStream
fis) throws IOException
{
DefaultMutableTreeNode outNode = null;
int iCurLevel = 0;
Vector vLevels = new Vector();
BufferedReader br = new BufferedReader(
new InputStreamReader(fis));
String sLine = null;
while ( (sLine = br.readLine()) != null)
{
if (debug) System.out.println("Line: " + sLine);
// get position of token
int pos = countWhiteSpace(sLine);
DefaultMutableTreeNode aNode = new DefaultMutableTreeNode
(sLine.trim());
vLevels.addElement(new LevelNode(pos, aNode));
if (outNode == null)
{
outNode = aNode;
}
else
{
// find who to add this node to
DefaultMutableTreeNode parent = findParent(vLevels, pos);
if (parent != null)
{
parent.add(aNode);
}
}
}
return outNode;
}
/** Constructor. */
public TocTreePanel(String sTocFile) throws IOException
{
setLayout(new BorderLayout());
// check if file exists
File f = new File(sTocFile);
if (f.exists())
{
FileInputStream fis = new FileInputStream(sTocFile);
dynamicTree = parseTableOfContents(fis);
fis.close();
}
else
throw new IOException(sTocFile + " does not exist.");
if (dynamicTree != null)
{
// create a JTree
jt = new JTree(dynamicTree);
// get the Tree Model
jtm = jt.getModel();
// listen to the selections
tsm = jt.getSelectionModel();
tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tsm.addTreeSelectionListener(this);
// create a scrollPane
JScrollPane scrollpane = new JScrollPane();
scrollpane.getViewport().add(jt);
add("Center", scrollpane);
}
else
throw new IOException(sTocFile + " is empty.");
}
public void valueChanged(TreeSelectionEvent tse)
{
// get the path selected
TreePath tp = tse.getPath();
// get the leaf node of the path
Object o = tp.getLastPathComponent();
// for now, just print out the leaf node (a String)
System.out.println(o);
}
/** Main method for unit testing. */
public static void main(String args[])
{
if (args.length < 1)
{
System.out.println("USAGE: java TocTreePanel tocFile");
System.exit(1);
}
TocTreePanel.debug = true;
try
{
TocTreePanel tp = new TocTreePanel(args[0]);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
System.exit(0);
}
}
---------------------------------------------------------------------
/** TocFrame.java */
package jwiley.chp21;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
/**
* Simple Frame to demonstrate a dynamic use for a
* JTree.
* @author Michael C. daconta
* @see TocTreePanel
*/
public class TocFrame extends Frame
{
/** Simple adapter class to shutdown the application
when the close button is pushed. */
class ShutdownAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{ System.exit(0); }
}
/** Constructor.
* @param sTocFile Name of ".toc" file.
*/
public TocFrame(String sTocFile)
{
super(sTocFile);
TocTreePanel tp = null;
try
{
tp = new TocTreePanel(sTocFile);
add("Center", tp);
} catch(IOException ioe)
{ }
addWindowListener(new ShutdownAdapter());
setSize(200,200);
setLocation(50,50);
setVisible(true);
}
/** Main() method to invoke from the JVM. */
public static void main(String args[])
{
if (args.length < 1)
{
System.out.println("USAGE: java TocFrame tocFile");
System.exit(1);
}
new TocFrame(args[0]);
}
}
-------------------------------------------------------------------
/** TestTableFrame.java */
package jwiley.chp21;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
/**
* Frame to test the JTable component.
* @author Eric Monk
*/
public class TestTableFrame extends JFrame
{
/** constructor. */
public TestTableFrame (String sTitle)
{
super(sTitle);
// create data model
DatabaseTableModel dataModel = null;
try {
dataModel
new DatabaseTableModel("jdbc:odbc:ExampleDB",
"Books");
} catch (Exception e)
{
System.out.println("Cannot get data model. Error: "
+ e.toString());
System.exit(0);
}
// create table
JTable table = new JTable(dataModel);
// Put the table and header into a scrollPane
JScrollPane scrollpane = new JScrollPane(table);
getContentPane().add("Center", scrollpane);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{ System.exit(0); }
});
setLocation(50,50);
pack();
show();
}
/** main method to invoke from the JVM. */
public static void main (String args[])
{
new TestTableFrame("Test Table Frame");
}
}
----------------------------------------------------------------
date file "book.toc" - ( to run would type java TocFrame book.toc )
----------------------------------------------------------------
Java and JavaScript for C/C++ Programmers
Part I Java Language
Chapter 1 Introduction to Java
Chapter 2 Comparing Java to ANSI C
Chapter 3 Comparing Java to C++
Chapter 4 Language Features Not Shared
Chapter 5 Connect to Legacy Code
Part II Java Packages
Chapter 6 lang
Chapter 7 util
Chapter 8 io
Chapter 9 net
Chapter 10 awt
Chapter 11 beans
Chapter 12 applet
Chapter 13 idl
Chapter 14 java2D
Chapter 15 math
Chapter 16 rmi
Chapter 17 security
Chapter 18 sql
Chapter 19 text
Chapter 20 Servlet
Chapter 21 JavaMedia
Chapter 22 MS-COM & DCOM
Chapter 23 Java Foundation Classes
Part III JavaScript
Chapter 24 Comparing JavaScript to Java
Chapter 25 Calling Java from JavaScript
Part IV Appendices
Appendix A Coding Conventions
Appendix B References
-------------------------------------------------------------------
/** DatabaseTableModel.java */
package jwiley.chp21;
import java.sql.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
/**
* DataModel for the JTable component.
* @author Eric Monk
* @author Mike Daconta
*/
public class DatabaseTableModel extends DefaultTableModel
{
/** Constructor to build data for JTable by querying any jdbc
* table.
* @param sDatabaseURL - url connection to database in jdbc format.
* @param sTable - table name to query.
*/
public DatabaseTableModel (String sDatabaseURL, String sTable) throws
Exception
{
try
{
// Load database driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException cnfe)
{
throw new Exception("Error initializing database driver. " +
"Error: " + cnfe.toString());
}
// getMetaData - column headings
// get all data from table
try
{
// Establish connection
Connection con = DriverManager.getConnection(sDatabaseURL);
// Create and send statement
String sQuery = "SELECT * FROM " + sTable;
Statement stmt = con.createStatement();
ResultSet rslt = stmt.executeQuery(sQuery);
ResultSetMetaData rsmd = rslt.getMetaData();
int iNumColumns = rsmd.getColumnCount();
String [] sColumnHeadings = new String[iNumColumns];
for (int iCount = 0; iCount < sColumnHeadings.length; iCount++)
sColumnHeadings[iCount] = rsmd.getColumnName(iCount + 1);
setColumnIdentifiers(sColumnHeadings);
// Process data
while (rslt.next())
{
String sDataForRow[] = new String[sColumnHeadings.length];
for (int iCount = 0; iCount < sColumnHeadings.length;
iCount++)
{
sDataForRow[iCount] = rslt.getString(iCount + 1);
}
addRow(sDataForRow);
}
// Cleanup
rslt.close();
stmt.close();
con.close();
} catch (SQLException sqle)
{
while (sqle != null)
{
System.out.println ("SQLState: " +
sqle.getSQLState ());
System.out.println ("Message: " +
sqle.getMessage ());
System.out.println ("ErrorCode: " +
sqle.getErrorCode ());
sqle = sqle.getNextException ();
}
throw new Exception ("Database error has occurred. " +
"Error: " + sqle.toString());
}
}
}
-----------------------------------------------------------------------
|
|
 |