• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassCastException

 
Pathma Rathinavelu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am running a Java applet, and i get the applet notinited error. I checked the Java console from control panel and found the following exception. any clue, why this happens?


java.lang.ClassCastException

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

thanks
Pathma,TUHH
 
Pathma Rathinavelu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if someone wonders about the code that i have written, i am pasting it here. sorry its a bit too much, however!


I am using a free library called Chart2D from sourceforge.net.

I have used it http://chart2d.sourceforge.net/ and written the following. I get APPLET NOTINITED error when i load the applet, so i checked for the exception in Java console from control panel and it says java.lang.ClassCastException

++++++++++++
code
++++++++++++


import net.sourceforge.chart2d.*;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import java.awt.Color;
import java.util.Random;
import java.io.*;

/**
* A Chart2D demo demonstrating the LBChart2D object.
* Container Class: JFrame<br>
* Program Types: Applet or Application<br>
*/
public class LBChart2DFrameDemo extends JApplet {

//Data for reading from file

private JFrame frame = null;
private static boolean isApplet = true;


/**
* For running as an application.
* Calls init() and start().
* @param args An unused parameter.
*/
public static void main (String[] args) {

isApplet = false;
LBChart2DFrameDemo demo = new LBChart2DFrameDemo();
demo.init();
demo.start();
//exit on frame close event
}


/**
* Configure the chart and frame, and open the frame.
*/
public void init() {

//Start configuring a JFrame GUI with a JTabbedPane for
multiple chart panes
JTabbedPane panes = new JTabbedPane();

panes.addTab ("Line", getChart2DDemoF());
//for scaling dymanically
boolean dynamicSizeCalc = false;
if (dynamicSizeCalc) {
int maxWidth = 0;
int maxHeight = 0;
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.pack();
Dimension size = chart2D.getSize();
maxWidth = maxWidth > size.width ? maxWidth :
size.width;
maxHeight = maxHeight > size.height ? maxHeight :
size.height;
}
Dimension maxSize = new Dimension (maxWidth, maxHeight);
System.out.println (maxSize);
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.setSize (maxSize);
chart2D.setPreferredSize (maxSize);
}
System.out.println (panes.getPreferredSize());
}
else {
Dimension maxSize = new Dimension (561, 214);
for (int i = 0; i < panes.getTabCount(); ++i) {
Chart2D chart2D = (Chart2D)panes.getComponentAt (i);
chart2D.setSize (maxSize);
chart2D.setPreferredSize (maxSize);
}
panes.setPreferredSize (new Dimension (566 + 5, 280 +
5)); //+ 5 slop
}

frame = new JFrame();
frame.getContentPane().add (panes);
frame.setTitle ("NWR Vs Cycles Graph");
frame.addWindowListener (
new WindowAdapter() {
public void windowClosing (WindowEvent e) {
destroy();
} } );
frame.pack();
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation (
(screenSize.width - frame.getSize().width) / 2,
(screenSize.height - frame.getSize().height) / 2);


}


/**
* Shows the JFrame GUI.
*/
public void start() {
frame.show();
}

static int count=0;
public String[] readXAxisFile()
{
String[] xAxisValues= new String[1000];
String text;
try
{
FileReader inputFile = new
FileReader("E:/11th/nwr/output/xaxis.dat");;
BufferedReader fileInput = new BufferedReader(inputFile);
int k=0;
while((text =
fileInput.readLine()).compareTo(("###")) != 0)
{
xAxisValues[k++]=text;
count++;
}
inputFile.close();
return xAxisValues;
}

catch(IOException e)
{
System.out.println(e.getMessage());
return null;
}
}


public float[] readYAxisFile()
{
float[] yAxisValues= new float[1000];
String text;
try
{
FileReader inputFile = new
FileReader("E:/11th/nwr/output/nwr.dat");;
BufferedReader fileInput = new BufferedReader(inputFile);
int k=0;
while((text =
fileInput.readLine()).compareTo(("###")) != 0)
{
yAxisValues[k++]=Float.parseFloat(text);
}
inputFile.close();
return yAxisValues;
}

catch(IOException e)
{
System.out.println(e.getMessage());
return null;
}
}

/**
* Ends the application or applet.
*/
public void destroy() {

if (frame != null) frame.dispose();
if (!isApplet) System.exit (0);
}


/**
* Builds the demo chart.
* @return The demo chart.
*/
private Chart2D getChart2DDemoF() {

//<-- Begin Chart2D configuration -->

//Configure object properties
Object2DProperties object2DProps = new Object2DProperties();
object2DProps.setObjectTitleText ("NWR Vs Cycles");

//Configure chart properties
Chart2DProperties chart2DProps = new Chart2DProperties();

//Configure legend properties
LegendProperties legendProps = new LegendProperties();
String[] legendLabels = {"NWR"};
legendProps.setLegendLabelsTexts (legendLabels);

//Configure graph chart properties
GraphChart2DProperties graphChart2DProps = new
GraphChart2DProperties();

String[] xAxis = readXAxisFile();

graphChart2DProps.setLabelsAxisLabelsTexts (xAxis);
graphChart2DProps.setLabelsAxisTitleText ("Cycles");
graphChart2DProps.setNumbersAxisTitleText ("NWR");
graphChart2DProps.setChartDatasetCustomizeGreatestValue
(true);
graphChart2DProps.setChartDatasetCustomGreatestValue (1000);
graphChart2DProps.setLabelsAxisTicksAlignment
(graphChart2DProps.CENTERED);

//Configure graph properties
GraphProperties graphProps = new GraphProperties();
graphProps.setGraphBarsExistence (false);
graphProps.setGraphLinesExistence (true);
graphProps.setGraphOutlineComponentsExistence (true);
graphProps.setGraphAllowComponentAlignment (true);

//Configure dataset

// For y-axis values - NWR values

Dataset dataset = new Dataset (1, count, 1);

float[] yAxis = readYAxisFile();
for(int c=0;c<count;c++)
{
dataset.set (0, c, 0, yAxis[c]);
}

//Configure graph component colors
MultiColorsProperties multiColorsProps = new
MultiColorsProperties();


//Configure chart
LBChart2D chart2D = new LBChart2D();
chart2D.setObject2DProperties (object2DProps);
chart2D.setChart2DProperties (chart2DProps);
chart2D.setLegendProperties (legendProps);
chart2D.setGraphChart2DProperties (graphChart2DProps);
chart2D.addGraphProperties (graphProps);
chart2D.addDataset (dataset);
chart2D.addMultiColorsProperties (multiColorsProps);

//Optional validation: Prints debug messages if invalid
only.
if (!chart2D.validate (true)) chart2D.validate (false);

//<-- End Chart2D configuration -->

return chart2D;
}


********************

Pathma
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see the HTML; perhaps you're naming the wrong class.

Does this run correctly as an application (given that it's got a "main" routine?)
 
Pathma Rathinavelu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your reply.

It dosent run as an application, i have no idea why it is so. I get an exception there also. which is this.

java.lang.NoClassDefFoundError: Chart2D/LBChart2DFrameDemo (wrong name: LBChart2DFrameDemo)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"


My HTML file is quite simple.

here it goes.


<html>
<head>
<title>LBChart2DFrameDemo</title>
</head>
<body>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p align="center"><b>LBChart2DFrameDemo</b></p>
<APPLET CODE="LBChart2DFrameDemo.class"
WIDTH="0" HEIGHT="0">
<PARAM NAME="archive" VALUE="Chart2D.jar">
</APPLET>
</td>
</tr>
</table>
</div>
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic