Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Error in Loading Applets

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//Following is the error log I receive

java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException

//
Below is the Java Code

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;

import javax.swing.*;
import ChartDirector.*;
public class CERMeter extends Applet{

String finalImage=null;
Graphics graphics=null;
Image image;
Image image1;
ImageObserver obs ;
public void init()
{


}



//Name of demo program
public String toString() {
return "CER Meter";

}

//Number of charts produced in this demo
public int getNoOfCharts() {
return 1;

}
//Main code for creating charts
public Image createChart(ChartViewer viewer, int index)
{
// The value to display on the meter
double value = 60;

// Create an AugularMeter object of size 200 x 200 pixels, with silver
// background, black border, 2 pixel 3D depressed border and rounded corners.
AngularMeter m = new AngularMeter(200, 200, Chart.silverColor(), 0x000000, -2
);
m.setRoundedFrame();

// Set the meter center at (100, 100), with radius 85 pixels, and span from
// -135 to +135 degress
m.setMeter(100, 100, 85, -135, 135);

// Meter scale is 0 - 100, with major tick every 10 units, minor tick every 5
// units, and micro tick every 1 units
m.setScale(0, 100, 10, 5, 1);

// Disable default angular arc by setting its width to 0. Set 2 pixels line
// width for major tick, and 1 pixel line width for minor ticks.
m.setLineWidth(0, 2, 1);

// Set the circular meter surface as metallic blue (9999DD)
m.addRing(0, 90, Chart.metalColor(0x9999dd));

// Add a blue (6666FF) ring between radii 88 - 90 as decoration
m.addRing(88, 90, 0x6666ff);

// Set 0 - 60 as green (99FF99) zone, 60 - 80 as yellow (FFFF00) zone, and 80
// - 100 as red (FF3333) zone
m.addZone(0, 60, 0x99ff99);
m.addZone(60, 80, 0xffff00);
m.addZone(80, 100, 0xff3333);

// Add a text label centered at (100, 135) with 15 pts Arial Bold font
m.addText(100, 135, "CER", "Arial Bold", 15, Chart.TextColor, Chart.Center);

// Add a text box centered at (100, 165) showing the value formatted to 2
// decimal places, using white text on a black background, and with 1 pixel
// 3D depressed border
m.addText(100, 165, m.formatValue(value, "2"), "Arial", 8, 0xffffff,
Chart.Center).setBackground(0x000000, 0x000000, -1);

// Add a semi-transparent blue (40333399) pointer at the specified value
m.addPointer(value, 0x40333399);

// Output the chart
viewer.setImage(m.makeImage());
image=m.makeImage();
return image;
}

public void paint(Graphics g){
CERMeter demo = new CERMeter();
ChartViewer viewer = new ChartViewer();
image1=demo.createChart(viewer, 0);


//graphics = image.getGraphics();

g.drawImage(image1,100,100,this);


}

public CERMeter()
{

}


}
//Below is the JSP Code which I call to Load Applets

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="ChartDirector.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table width="90%" border="0" align ="center" cellpadding="5" cellspacing="0">
<tr>
<td align="center" >
<APPLET CODE="CERMeter.class" HEIGHT=200 WIDTH=310>



</APPLET>
</td>


</body>
</html>


//*********Code Ends****************//

In Java when I run as Applet it runs fine but when I run through JSP It gives above error.

I have Included ChartDirector.jar and both JSP and JavaClass are in same folder.

Please help me to resolve the same.

Looking forward for an earliest reply

Regards

Anurag Pathak

pathak_arg@yahoo.com



 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please edit your post to UseCodeTags. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.

The ChartDirector.jar file must be referenced in the applet tag through an "archive" attribute. That's probably not the cause of the exception, though.

What is this:

public CERMeter()
{
}

 
Anurag Pathak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Please edit your post to UseCodeTags. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.

The ChartDirector.jar file must be referenced in the applet tag through an "archive" attribute. That's probably not the cause of the exception, though.

What is this:

public CERMeter()
{
}



Thanks for Suggestion I will follow it in future.
But how to run the code please guide me where I am going wrong I will be very greatfull
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks as if the error message above is incomplete; is there more to it in the Java Console?

Have you fixed the issue with the missing archive attribute by now?

CERMeter demo = new CERMeter();


Never, ever, use a constructor in an applet. The browser JVM calls the no-argument constructor when it starts the applet - your code has no business doing that.
 
Anurag Pathak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:It looks as if the error message above is incomplete; is there more to it in the Java Console?

Have you fixed the issue with the missing archive attribute by now?

CERMeter demo = new CERMeter();


Never, ever, use a constructor in an applet. The browser JVM calls the no-argument constructor when it starts the applet - your code has no business doing that.



I have put in another method and added archive also still its not working .

I am not able to figure it out specific problem.

Please guide me with some sample code
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the code -using CODE tags- and the HTML tag that you're now using, and the full stack trace of the exception.
 
Anurag Pathak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Please post the code -using CODE tags- and the HTML tag that you're now using, and the full stack trace of the exception.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic