LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java, code compiles and supposedly runs fine in windows, but not linux (https://www.linuxquestions.org/questions/programming-9/java-code-compiles-and-supposedly-runs-fine-in-windows-but-not-linux-157334/)

exodist 03-13-2004 11:23 PM

Java, code compiles and supposedly runs fine in windows, but not linux
 
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: //MenuBalloon/class

when I run this code that I downloaded from a website, it is part of a book and it says it works in windows and unix. It compiles fine. I also wrote my own program based on it that is completely different and also compiles fine.

http://www.shu.ac.uk/java/3rdEdition...enuBalloon.txt
is the books code

my code is:
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Assign10 extends Frame implements ActionListener, WindowListener
{

private MenuItem New, Open, Delete;
private MenuItem Undo, Redo, Cut, Copy, Paste;
private String TheString = new String("Select a menu item");

public static void main(String[] args)
{
Frame f = new Assign10();
f.setSize(300, 300);
f.setVisible(true);
}

public Assign10()
{
setTitle("MenuThingy :-D");

MenuBar menuBar = new MenuBar();

Menu fileMenu = new Menu("File");
Menu editMenu = new Menu("Edit");

New = new MenuItem("New");
fileMenu.add(New);
New.addActionListener(this);

Open = new MenuItem("Open");
fileMenu.add(Open);
Open.addActionListener(this);

Delete = new MenuItem("Delete");
fileMenu.add(Delete);
Delete.addActionListener(this);


Undo = new MenuItem("Undo");
editMenu.add(Undo);
Undo.addActionListener(this);

Redo = new MenuItem("Redo");
editMenu.add(Redo);
Redo.addActionListener(this);

editMenu.addSeparator();

Cut = new MenuItem("Cut");
editMenu.add(Cut);
Cut.addActionListener(this);

Copy = new MenuItem("Copy");
editMenu.add(Copy);
Copy.addActionListener(this);

Paste = new MenuItem("Paste");
editMenu.add(Paste);
Paste.addActionListener(this);

menuBar.add(fileMenu);
menuBar.add(editMenu);
setMenuBar(menuBar);
addWindowListener(this);
}

public void actionPerformed(ActionEvent event)
{
if (event.getSource() == New)
{
TheString = new String("You Selected New");
}
if (event.getSource() == Open)
{
TheString = new String("You Selected Open");
}
if (event.getSource() == Delete)
{
TheString = new String("You Selected Delete");
}
// MenuItem Undo, Redo, Cut, Copy, Paste;
if (event.getSource() == Undo)
{
TheString = new String("You Selected Undo");
}
if (event.getSource() == Redo)
{
TheString = new String("You Selected Redo");
}
if (event.getSource() == Cut)
{
TheString = new String("You Selected Cut");
}
if (event.getSource() == Copy)
{
TheString = new String("You Selected Copy");
}
if (event.getSource() == Paste)
{
TheString = new String("You Selected Paste");
}
repaint();
}

public void paint (Graphics g)
{
g.drawString(TheString,20,20);
}

public void windowClosing(WindowEvent e)
{
System.exit(0);
}

public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
}

i compile with javac ./filename.java

exodist 03-13-2004 11:39 PM

lol strange ./ was the problem?

german 03-14-2004 11:19 PM

Quote:

Originally posted by exodist
no wait.. I think I will need a lot of secs
haha I need a lot of secs too... but I can never find the women to provide it

lucasbl3 03-16-2004 01:02 PM

I donīt think there is a problem in the code but rather in the command you use for invoking it.
Could you send the exact command line that you use for running this program (with all the arguments) ?

exodist 03-16-2004 01:47 PM

I already clarified, I used java ./whatever.class, the ./ was the problem, so was the .class, I had to type java whatever


All times are GMT -5. The time now is 12:32 PM.