473,463 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Java Newbie Problem

2
Hello there,

I'm brand new to Java and have. I'm taking my 2nd Java class at school and I'm pretty lost at this point.

The main problem I'm having right now is I cannot get my code to execute. My code will compile, but when I try to execute it, either just using the "java" command or executing from TextPad, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: MortgagePayment1
Press any key to continue . . .



In my last class, my compiler was working fine and I could easily execute all of my applications. However, I stupidly ran Windows Updates and it installed Java 6 on my computer and nothing has worked right since.

When I execute "java -version" from a command line, this is what I get:

java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)


Here's the code I've compiled and am trying to execute:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.text.DecimalFormat;

public class MortgagePayment1 extends JFrame implements ActionListener
{

private JTextField mortgageAmount;
private JTextField mortgageTerm;
private JTextField interestRate;
private JTextField mortgagePaymentAmount;
private JButton calculateBtn;
private JButton quitBtn;


public MortgagePayment1() {

JPanel contentPane = (JPanel)getContentPane();
contentPane.setLayout(new BorderLayout(0, 4));
JPanel northPanel = new JPanel();
Border b = BorderFactory.createEtchedBorder();

northPanel.setBorder(BorderFactory.createTitledBor der(b, "Calculate Mortgage Payment", TitledBorder.TOP, TitledBorder.CENTER));

northPanel.setLayout(new GridLayout(4, 2, 10, 10));


JLabel mortgageAmountLabel = new JLabel("Input Initial Mortgage Amount (dollars)", JLabel.RIGHT);
JLabel mortgageTermLabel = new JLabel("Input Mortgage Term (years)", JLabel.RIGHT);
JLabel interestRateLabel = new JLabel("Input Interest Rate", JLabel.RIGHT);
JLabel mortgagePaymentAmountLabel = new JLabel("Mortgage Payment Amount", JLabel.RIGHT);

mortgageAmount = new JTextField(10);
mortgageTerm = new JTextField(10);
interestRate = new JTextField(10);
mortgagePaymentAmount = new JTextField(10);

northPanel.add(mortgageAmount);
northPanel.add(mortgageTerm);
northPanel.add(interestRate);
northPanel.add(mortgagePaymentAmount);
northPanel.add(mortgageAmountLabel);
northPanel.add(mortgageTermLabel);
northPanel.add(interestRateLabel);
northPanel.add(mortgagePaymentAmountLabel);
// add the rest of labels and textfields

JPanel southPanel = new JPanel();

calculateBtn = new JButton("Calculate");
southPanel.add(calculateBtn);

calculateBtn.addActionListener(this);

quitBtn = new JButton("Quit");
southPanel.add(quitBtn);

quitBtn.addActionListener(this);

contentPane.add(northPanel, BorderLayout.NORTH);
contentPane.add(southPanel, BorderLayout.SOUTH);

}

public void actionPerformed(ActionEvent evt)
{

JButton sourceBtn = (JButton)evt.getSource();

if (sourceBtn == calculateBtn)
{
//calculate monthly payment

//.... set mortgagePaymentAmount textfield to monthly payment.
}

else if (sourceBtn == quitBtn)
{
System.exit(0);
}

}//close actionPerformed method


public static void main(String[] args)
{

MortgagePayment1 mp1 = new MortgagePayment1();

mp1.setTitle("Mortgage Payment: Assignment 1 developed by ...");
mp1.pack();
mp1.addWindowListener(new WindowAdapter()
{

public void windowClosing(WindowEvent e)
{

Window w = e.getWindow();

w.setVisible(false);
w.dispose();

System.exit(0);

}//close windowClosing method

});//close addWindowListener method


mp1.setVisible(true);

}//close Main method

}//close MortgagePayment1 class


Any help would be greatly appreciated.
May 5 '07 #1
3 1967
JosAH
11,448 Expert 8TB
Exception in thread "main" java.lang.NoClassDefFoundError: MortgagePayment1
Press any key to continue . . .
Your Java virtual machine simply can't find the file MortgagePayment1.class.
You need to tell it where it is. This is how you do it:

1) go to the directory where the class is stored.
2) type:
Expand|Select|Wrap|Line Numbers
  1. java -classpath . MortgagePayement1
note the space-dot-space following the "-classpath" flag. This tells Java to look
for classes in the current working directory.

kind regards,

Jos
May 6 '07 #2
pnolan
2
Hi there,

Thanks for the response. I did what you said, but I got the following error:

C:\Java407>java -classpath . MortgagePayment1
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
umber in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)


You should know that since my original posting, I went in and uninstalled "ALL" my Java components and went back to Java 5 update 11. When I run java -version now I get:

java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
May 8 '07 #3
JosAH
11,448 Expert 8TB
Recompile your MortgagePayment1.java source file and everything should be fine.
You currently have a version problem, that's why your JVM is throwing an error.

kind regards,

Jos
May 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
6
by: Robbie Baldock | last post by:
Hi - I'm a bit of a newbie to the world of XSLTs but am trying to call a Java method on a parameter passed into an XSLT but am having problems. I've stripped the XSLT down to its bare bones: ...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
7
by: vj | last post by:
Hello Group, I am C++/OOP newbie and was working on a project when i came accross this puzzleing problem with inheritence. C++ Code ================== class Parent {
4
by: Abram Friesen | last post by:
Hi all, I'm a newbie at DB2 and trying to create a simple java UDF. When I call my function, I'm receiving SQL4306N. Could someone please tell me what I'm doing wrong here? Here is my java...
30
by: Richard | last post by:
Level: Java newbie, C experienced Platform: Linux and Win32, Intel Another programmer and I are working on a small project together. He's writing a server process in Java that accepts input...
8
by: Aravind | last post by:
hi, some of my friends told that python and java are similar in the idea of platform independency. Can anyone give me an idea as i'm a newbie to java and python but used to C++. My idea is to...
1
by: Swapnil Kale | last post by:
Hi, I'm working on a Migration project (Forte to JAVA). The forte client had a C++ dll which used to call one more FORTE dll for a complex database calculations. Now all the forte code has...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.