Applet not inited

A

Allan Bruce

Hi there,

I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?

Thanks
Allan


/*
* FibonacciTest.java
*
* Created on 10 November 2003, 11:16
*/

/**
*
* @author abruce
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class FibonacciTest extends JApplet implements ActionListener
{
JLabel numberLabel, resultLabel, timeLabel;
JTextField numberField, resultField, timeField;

public void init() // set up the GUI
{
// obtain content pane and set its layout to FlowLayout
Container container = getContentPane();
container.setLayout(new FlowLayout());

// create numberLabel and attach it to content pane
numberLabel = new JLabel("Enter an integer and press Enter");
container.add(numberField);

// create numberField and attach it to content pane
numberField = new JTextField(10);
container.add(numberField);

// register this applet as numberFields ActioNListener
numberField.addActionListener(this);

// create resultLabel and attach it to conmetnt pane
resultLabel = new JLabel("Fibbonaci value is");
container.add(resultLabel);

// create timeLabel and attach it to content pane
timeLabel = new JLabel("Time taken was: ");
container.add(timeLabel);

// create numberField, make it uneditable and attach to content pane
resultField = new JTextField(15);
resultField.setEditable(false);
container.add(resultField);
} // end init

public void actionPerformed(ActionEvent e)
{
long number, fibonacciValue;

// obtain users input and convert to long
number = Long.parseLong(numberField.getText());

showStatus("Calculating");

// calculate fibonacci value for number from user input
fibonacciValue = fibonacci(number);

showStatus("Done");
resultField.setText(Long.toString(fibonacciValue));
} // end actionPerformed

// recursive fibonacci
public long fibonacci(long n)
{
// base case
if (n==0 || n==1)
return n;
else
return fibonacci(n-1) + fibonacci(n-1);
} // end fibonacci
} // end FibonacciTest


--
Allan Bruce
Dept. of Computing Science
University of Aberdeen
Aberdeen AB24 3UE
Scotland, UK
 
A

Andrew Thompson

....
I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?

At a first guess I would say you use IE6 on XP?
The error you describe is common for that particular
browser.

The browser you use does not support the
required Java version.

Try the page at http://www.physci.org/test/JRE/.
Specifically designed to test JVM version for any
given browser.
 
A

Allan Bruce

Andrew Thompson said:
...

At a first guess I would say you use IE6 on XP?
The error you describe is common for that particular
browser.

The browser you use does not support the
required Java version.

Try the page at http://www.physci.org/test/JRE/.
Specifically designed to test JVM version for any
given browser.

Yes, I do use XP/IE6, but I had a look at that page and it seems to be fine.
I have written other small applets and they seem to be fine. This is the
first one I have had trouble with.
Allan
 
A

Andrew Thompson

Allan Bruce said:
when
....

Yes, I do use XP/IE6, but I had a look at that page and it seems to be
fine.

What does that mean? Your IE 6 should see
all versions up to 1.4, but redirect for 1.5 if
it has the latest Java plug-in.
I have written other small applets and they seem to be fine. This is the
first one I have had trouble with.

Is this the first one using Swing?
 
A

Allan Bruce

Andrew Thompson said:
fine.

What does that mean? Your IE 6 should see
all versions up to 1.4, but redirect for 1.5 if
it has the latest Java plug-in.

Yup, thats what happens - I also updated just incase but still the same.
Is this the first one using Swing?

Nope, I have used swing before too. The only thing that this program doesnt
have is a paint() method, whereas my previous swing applets have. Could
this be the problem?
Thanks
Allan
 
P

Peter J. Grey

Hi!

Allan said:
Hi there,

I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?

You have a typo:

// create numberLabel and attach it to content pane
numberLabel = new JLabel("Enter an integer and press Enter");
container.add(numberField);

numberField should be numberLabel - numberField is not yet initialized at this
point, meaning it's null, and the applet is throwing a
java.lang.NullPointerException.

Peter
 
A

Andrew Thompson

Browser confirmed using Java 1.4

Allan Bruce said:
Hi there,

I thought I'd reply to _this_ message 'cos it has your code.
I am learning java and have copied this code from my textbook, but when I
try to run the applet, I get an error "Applet not inited". Can anybody shed
some light on this error?

What is the stack trace recorded in the Java console?
[ It is available under the 'Tools' menu. ]
 
A

Allan Bruce

Peter J. Grey said:
Hi!



You have a typo:

// create numberLabel and attach it to content pane
numberLabel = new JLabel("Enter an integer and press Enter");
container.add(numberField);

numberField should be numberLabel - numberField is not yet initialized at this
point, meaning it's null, and the applet is throwing a
java.lang.NullPointerException.

Peter

Thanks, Thats it :eek:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top