Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » java.lang.NoClassDefFoundError(Cannot determine what is causing java.lang.NoClassDefFoundError)
java.lang.NoClassDefFoundError [message #902295] Thu, 16 August 2012 16:26 Go to next message
Gary Monnier is currently offline Gary Monnier
Messages: 6
Registered: August 2012
Junior Member
Hi,

I written a java app to read a PC flat file and it works fine. Now I'm trying to adapt my app to read directly from an IBM i5.

I'm using jt400 to access the i5. I've successfully imported the jt400 source into my project. Everything seems to compile but I continually receive the following error when I try to run my app.

java.lang.NoClassDefFoundError: org/test/swt/appwindow/testswt
Caused by: java.lang.ClassNotFoundException: org.test.swt.appwindow.testswt
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)
Exception in thread "main"

I'm using Eclipse Indigo Service Release 2 Build id 20120216-1857.

This has me stumped. Is it just a newbe error?

Does anyone have any idea as to what I might be doing wrong?

Thanks!
Re: java.lang.NoClassDefFoundError [message #902310 is a reply to message #902295] Thu, 16 August 2012 20:20 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1336
Registered: July 2009
Senior Member
On 08/16/2012 03:26 PM, Gary Monnier wrote:
> Hi,
>
> I written a java app to read a PC flat file and it works fine. Now I'm
> trying to adapt my app to read directly from an IBM i5.
>
> I'm using jt400 to access the i5. I've successfully imported the jt400
> source into my project. Everything seems to compile but I continually
> receive the following error when I try to run my app.
>
> java.lang.NoClassDefFoundError: org/test/swt/appwindow/testswt
> Caused by: java.lang.ClassNotFoundException: org.test.swt.appwindow.testswt
> 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)
> Exception in thread "main"
> I'm using Eclipse Indigo Service Release 2 Build id 20120216-1857.
>
> This has me stumped. Is it just a newbe error?
> Does anyone have any idea as to what I might be doing wrong?
>
> Thanks!
You are trying to run a class called org.test.swt.appwindow.testswt but
the class doesn't exist. The class name looks a little strange. What
is the fully qualified class name of your main class?
Re: java.lang.NoClassDefFoundError [message #903017 is a reply to message #902310] Tue, 21 August 2012 12:21 Go to previous messageGo to next message
Gary Monnier is currently offline Gary Monnier
Messages: 6
Registered: August 2012
Junior Member
I don't understand how it cannot exist. Class testswt shows as exiting under test.swt.

testswt is the .java I'm trying to run and org.test.swt.appwindow is the package testswt.java was placed in when I imported jt400.


All the jt400 imports were placed in packages within src.


Should I move the .javas to be under src?
Re: java.lang.NoClassDefFoundError [message #903030 is a reply to message #902310] Tue, 21 August 2012 13:06 Go to previous messageGo to next message
Gary Monnier is currently offline Gary Monnier
Messages: 6
Registered: August 2012
Junior Member
I moved the source code from org.test.swt.appwindow to src. This caused a default package to be created. This package did not exist after I imported jt400.

The moved source had the package statement stripped from it.

I tried running the .java but received the same error. As far as I can tell class testswt exists.

java.lang.NoClassDefFoundError: testswt
Caused by: java.lang.ClassNotFoundException: testswt
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)
Exception in thread "main"

Re: java.lang.NoClassDefFoundError [message #903031 is a reply to message #903017] Tue, 21 August 2012 13:06 Go to previous messageGo to next message
Russell Bateman is currently offline Russell Bateman
Messages: 3148
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 8/21/2012 10:21 AM, Gary Monnier wrote:
> I don't understand how it cannot exist. Class testswt shows as exiting under test.swt.
>
> testswt is the .java I'm trying to run and org.test.swt.appwindow is the package testswt.java was placed in when I imported jt400.
>
>
> All the jt400 imports were placed in packages within src.
>
>
> Should I move the .javas to be under src?
>

It increases the difficulty in communication when the one being
supported is doing the unexpected, in this case, failing to follow Java
naming convention. Without your illustration, one is tempted to see
org.test.swt.appwindow.testswt as a package and not a class. From the
illustration it's clear that your class is testswt and that it has a
main, which looks good as far as it goes (can't see the code to that
class, but void main( String[] ) looks okay.

Your ".javas" are already under src. These would be, notably, testswt.java.

It's the rest of the stuff, which we can't see, that's buried under
packages. Typically, JARs (if that's what they are and certainly I'd
expect what's under java.math, java.net, java.sql, etc.) are placed
elsewhere and bound to the project by way of then Java Build Path ->
Libraries dialog.

My advice (and if you add 35 cents to it it's enough to make a phone
call if you can find a pay phone) would be to find a tutorial on how to
set up an Eclipse project. I would suggest starting here:

http://www.vogella.com/eclipseide.html
Re: java.lang.NoClassDefFoundError [message #903039 is a reply to message #903031] Tue, 21 August 2012 13:44 Go to previous messageGo to next message
Gary Monnier is currently offline Gary Monnier
Messages: 6
Registered: August 2012
Junior Member
Thanks for the suggestion Russell. I'll look at the tutorials again. It could be the way I set up the project but I haven't had this issue with the other 7 projects I've created to learn from org.eclipse.swt.examples.

Being newish to Java, and Eclipse outside IBM's RDi product, I'm sure I've made some convention naming errors and probably will do it again. I appreciate your patience.

I tried refactoring testswt to TestSwt but still receive the same error.

java.lang.NoClassDefFoundError: TestSwt
Caused by: java.lang.ClassNotFoundException: TestSwt
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)
Exception in thread "main"

The main java source is...


import java.util.*;
import java.sql.*;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;



public class TestSwt {

private static ResourceBundle resRespConflict = ResourceBundle.getBundle("responsibility_conflicts");
protected Shell shlTmsResponsibilities;
private Table table;
private SearchDialog searchDialog;

private String[] copyBuffer;

private static final String DELIMITER = "\t";
private static final String[] columnNames = {resRespConflict.getString("Responsibility_name"),
resRespConflict.getString("Conflicting_responsibility"),
resRespConflict.getString("Conflict_severity")};

/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
TestSwt window = new TestSwt();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shlTmsResponsibilities.open();
shlTmsResponsibilities.layout();
while (!shlTmsResponsibilities.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

/**
* Create contents of the window.
*/
protected void createContents() {
shlTmsResponsibilities = new Shell();
shlTmsResponsibilities.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
e.doit = closeConflictsList();
}
});
shlTmsResponsibilities.setSize(752, 510);
shlTmsResponsibilities.setText("TMS Responsibilities");

Menu menu = new Menu(shlTmsResponsibilities, SWT.BAR);
shlTmsResponsibilities.setMenuBar(menu);

MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
mntmFile.setText("File");

Menu menu_1 = new Menu(mntmFile);
mntmFile.setMenu(menu_1);

MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
mntmExit.setText("Exit");

MenuItem mntmCommunications = new MenuItem(menu, SWT.CASCADE);
mntmCommunications.setText("Communications");

Menu menu_2 = new Menu(mntmCommunications);
mntmCommunications.setMenu(menu_2);

MenuItem mntmConnect = new MenuItem(menu_2, SWT.NONE);
mntmConnect.setText("Connect");

MenuItem mntmDisconnect = new MenuItem(menu_2, SWT.NONE);
mntmDisconnect.setText("Disconnect");

MenuItem mntmSearch = new MenuItem(menu, SWT.CASCADE);
mntmSearch.setText("Search");

Menu menu_3 = new Menu(mntmSearch);
mntmSearch.setMenu(menu_3);

MenuItem mntmFind = new MenuItem(menu_3, SWT.NONE);
mntmFind.setText("Find");

MenuItem mntmFindNext = new MenuItem(menu_3, SWT.NONE);
mntmFindNext.setText("Find next");

MenuItem mntmHelp = new MenuItem(menu, SWT.CASCADE);
mntmHelp.setText("Help");

Menu menu_4 = new Menu(mntmHelp);
mntmHelp.setMenu(menu_4);

MenuItem mntmAbout = new MenuItem(menu_4, SWT.NONE);
mntmAbout.setText("About");

Composite composite = new Composite(shlTmsResponsibilities, SWT.V_SCROLL);
composite.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.NORMAL));
composite.setBounds(10, 10, 702, 417);

table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
table.setFont(SWTResourceManager.getFont("Tahoma", 12, SWT.NORMAL));
table.setBounds(0, 0, 692, 417);
table.setHeaderVisible(true);
table.setItemCount(1);
table.setLinesVisible(true);

table.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
table.setItemCount(0);

try{
// Register the driver
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
// Obtain a connection
Connection conn1 = DriverManager.getConnection("jdbc:as400:");
loadTheTable(conn1); // Load the display table
conn1.close(); // Close the connection
}catch(Exception e){
closeConflictsList();
}
}
});



TableColumn tblclmnResponsibility = new TableColumn(table, SWT.LEFT);
tblclmnResponsibility.setWidth(267);
tblclmnResponsibility.setText("Responsibility");

TableColumn tblclmnConflictingResponsibility = new TableColumn(table, SWT.LEFT);
tblclmnConflictingResponsibility.setWidth(329);
tblclmnConflictingResponsibility.setText("Conflicting Responsibility");

TableColumn tblclmnSeverity = new TableColumn(table, SWT.CENTER);
tblclmnSeverity.setWidth(89);
tblclmnSeverity.setText("Severity");

}

// Open the conflicts table



private boolean closeConflictsList() {
//ask user if they want to end
MessageBox box = new MessageBox(shlTmsResponsibilities, SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL);
box.setText(shlTmsResponsibilities.getText());
box.setMessage(resRespConflict.getString("Close_save"));

int choice = box.open();
if(choice == SWT.CANCEL) {
return false;
} else if(choice == SWT.YES) {
if (!closeConnection()) return false;
}

return true;
}

private boolean closeConnection() {

return true;
}

private boolean loadTheTable(Connection conn1) {

String query = "my sql string"; // Change to protect the innocent

try
{
Statement st = conn1.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
//String rsp = rs.getString(1);
//String cf = rs.getString(2);
//String sv = rs.getString(3);
// Set table items
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[]{rs.getString(1),rs.getString(2),rs.getString(3)});
}
}
catch (SQLException ex)
{
return false;
}
return true;
}


}


The responsibility_conflicts properties file contains the following.

Responsibility_name = Responsibility
Conflicting_responsibility = Conflicting responsibility
Conflict_severity = Severity
Title_bar = TMS Responsibility Conflicts -
File_menu_title = &File
Exit = E&xit
Search_menu_title = &Search
Find = &Find...\tCtrl+F
Find_next = Find &Next...\tF3
Help_menu_title = &Help
About = &About Responsibility Conflicts...
About_1 = About
About_2 = \nversion 1.0
OK = OK
Cancel = Cancel
Search_dialog_title = Find
Dialog_find_what = Fi&nd what:
Dialog_match_case = Match &case
Dialog_match_word = Match &whole word
Dialog_direction = Direction
Dialog_dir_up = &Up
Dialog_dir_down = &Down
Dialog_find = &Find
Cannot_find = Cannot find
Re: java.lang.NoClassDefFoundError [message #903069 is a reply to message #903031] Tue, 21 August 2012 15:33 Go to previous message
Gary Monnier is currently offline Gary Monnier
Messages: 6
Registered: August 2012
Junior Member
All,

Thanks for the suggestions. By following a combination of your suggestions I have the application window at least displaying.

I had to delete the project, end Eclipse, recreate the project, import jt400 jars into folder lib rather than import the source source then recreate the application window.

Thanks again.
Previous Topic:Subversive SVN Connectors not installing.
Next Topic:Setting External editor doesn't find correct program
Goto Forum:
  


Current Time: Fri Aug 22 09:44:54 EDT 2014

Powered by FUDForum. Page generated in 0.02303 seconds