Home » Newcomers » Newcomers » java.lang.NoClassDefFoundError(Cannot determine what is causing java.lang.NoClassDefFoundError)
| | | |
Re: java.lang.NoClassDefFoundError [message #903031 is a reply to message #903017] |
Tue, 21 August 2012 17:06 |
|
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 17:44 |
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
|
|
| |
Goto Forum:
Current Time: Tue Sep 24 06:07:44 GMT 2024
Powered by FUDForum. Page generated in 0.10073 seconds
|