Applet ClassNotFoundException and AppletClassLoader error

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
znasim
Posts: 10
Joined: Wed Feb 20, 2008 7:06 am

Applet ClassNotFoundException and AppletClassLoader error

Post by znasim » Thu Jun 05, 2008 3:00 pm

Dear David,

I completed one chart project which is having line,ohlc,candlestick and indicators like bollinger,sma,ema,maenvelope,RSI,DMI,Momentum. Its running perfectly. but now i want to run a static chart on applet bu using the historical data. Below i am sending my code what i have written for static chart. Please help me how i can solve the issue ClassNotFoundException and AppletClassLoader Problem.

Thanks and Regards




/*
<applet code="CCTools.WebChart.class" archive="jcommon-1.0.10.jar,jfreechart-1.0.6.jar" width=400 height=400>
</applet>

*/


package CCTools;
/*
* WebChart.java
*
* Created on May 29, 2008, 4:40 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

//package CCTools;

/**
*
* @author Zahid
*/
import Comm.StackModel;
import DataModel.UserProfileDataModel;
import XMLProcessor.ChartDataModel;
import XMLProcessor.ChartDataRequest;
import java.awt.Color;
import java.awt.Font;
import java.util.Date;
import java.util.TimeZone;
import javax.swing.JApplet;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.annotations.XYTextAnnotation;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.w3c.dom.Document;

public class WebChart extends Applet {

private String chartName;
PopUpMenuToolbar popupInstanceForSymbol = null;

private UserProfileDataModel _user;

Object[][] _result;

TimeSeries timeSeries;

public void init() {
_user=new UserProfileDataModel();
sendXMLToServer(popupInstanceForSymbol.returnCurrentSymbol());
// It is required but does not need anything.
}

// wrtitting a start methodd hints from internet
//
//public void start() {
//
//// createLineChart();
//}

// ennd zahid

// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
public void stop() {
// no actions needed here now.
}

// The standard method that you have to use to paint things on screen
// This overrides the empty Applet method, you can't called it "display" for example.

public void paint(Graphics g) {


createLineChart().draw((Graphics2D)g,getBounds());

//XYSeries series = new XYSeries("");
//series.add(1, 1);
//series.add(2, 2);
//series.add(3, 1);
//series.add(4, 9);
//series.add(5, 10);
//series.add(6, 60);
//
//XYSeriesCollection dataset = new XYSeriesCollection();
//dataset.addSeries(series);
//
//JFreeChart chart = ChartFactory.createXYLineChart("QATI", // Title
//"", // x-axis Label
//"", // y-axis Label
//dataset, // Dataset
//PlotOrientation.VERTICAL, // Plot Orientation
//false, // Show Legend
//true, // Use tooltips
//false // Configure chart to generate URLs?
//);
// chart.setAntiAlias(true);
//
//
//if ( chart!=null ) {
//chart.draw( (Graphics2D)g,getBounds()); //repaints the whole chart
//}

}

// code written for sending xml request to server

public void sendXMLToServer(String Symbol) {

Symbol=popupInstanceForSymbol.returnCurrentSymbol();
chartName="Line";
ChartDataModel cd = new ChartDataModel(_user);
ChartDataRequest _xml = new ChartDataRequest();
cd.setUser(_user);
cd.setID(8011);
cd.setParam_0_1("A");
cd.setStock_id(Integer.parseInt(MarketDataList.getData("StockID",Symbol)));
cd.setEventID(0001);
cd.setChartType(1);
cd.setChartPeriod(12);
cd.setChartFrequency(5);

if(!Symbol.equalsIgnoreCase("")) {
handleChartObjects(_xml , cd);
} else {

return;
}
}

// CODE WRITTEN FOR THE PURPOSE OF USING THREAD TO SEND XML



private JFreeChart createLineChart() {
ValueAxis timeAxis = new DateAxis("");
NumberAxis valueAxis = new NumberAxis("");
valueAxis.setAutoRangeIncludesZero(false);
XYDataset data = new TimeSeriesCollection(timeSeries);
XYItemRenderer renderer1 = new StandardXYItemRenderer();
// plot.getRendererForDataset(data).setBasePaint(Color.WHITE);
// plot.getRendererForDataset(data).setSeriesPaint(0,Color.WHITE);
// final CandlestickRenderer renderer1 = new CandlestickRenderer();
final DateAxis domainAxis = new DateAxis("");
final XYPlot plot = new XYPlot(data, domainAxis, valueAxis, renderer1);
// plot.getRendererForDataset(data).setBasePaint(Color.WHITE);
// plot.getRendererForDataset(data).setSeriesPaint(0,Color.WHITE);
plot.getRendererForDataset(data).setBasePaint(Color.LIGHT_GRAY);
plot.getRendererForDataset(data).setSeriesPaint(0,Color.LIGHT_GRAY);
// code added by zahid to show the last value of closing price into the line chart same will be followed into candle sticj and into ohlc
if(_result!=null) {
Date[] date = new Date[_result.length];
double[] close = new double[_result.length];
double c=close[_result.length-1] =((Float) _result[_result.length-1][5]).doubleValue();
date[_result.length-1] = (Date) _result[_result.length-1][0];
double d=(new Millisecond(0,date[_result.length-1].getSeconds(),date[_result.length-1].getMinutes(),date[_result.length-1].getHours(),date[_result.length-1].getDate(),date[_result.length-1].getMonth()+1,date[_result.length-1].getYear()+1900)).getLastMillisecond();
double c2 = (int)((c * 100)) / 100.0;

XYTextAnnotation xytextannotation = new XYTextAnnotation(""+c2, d, c);
xytextannotation.setPaint(new Color(49,92,242));
xytextannotation.setFont(new Font("SansSerif",Font.BOLD, 14));
plot.addAnnotation(xytextannotation);
}

// till here its code is completed and now its visible into line chart with red font
return new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}



public void handleChartObjects(ChartDataRequest charttObject, ChartDataModel chartDataModel) {
ChartData refreshThread = new ChartData(charttObject, chartDataModel);
Thread th = new Thread(refreshThread);
th.start();
}

public class ChartData implements Runnable {

ChartDataModel chartDataModel;
ChartDataRequest chartObject;
NewChartPage1 InstanceChartPage1;



public ChartData(ChartDataRequest _requestObject, ChartDataModel _baseDataModel){
chartDataModel = _baseDataModel;
chartObject = _requestObject;
}
public void run() {
chartDataModel.setXMLToServer(chartObject.extractXMLFromDataModel(chartDataModel));
System.out.println(chartObject.extractXMLFromDataModel(chartDataModel));
StackModel.add(chartDataModel);
//get the Data from the Xml
while(!(chartDataModel.getDataReceived()) ) {
if (chartDataModel.getParsingFailure()) {
System.out.println("Chart Data Is not Avialble");
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}

return;// approriate action to be taken
}
if(chartDataModel.getXMLFromServer().equals("")) {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
System.out.println("Exception in while making Thread Sleep for 2 seconds if data is not received from server!");
ex.printStackTrace();
}
} else {
Document doc = chartObject.getXMLDocument(chartDataModel.getXMLFromServer());
_result = chartObject.createBusinessObjectFromXML(doc,chartDataModel);
if(_result!=null) {
InstanceChartPage1.CCDataSet(_result);

chartDataModel.setDataReceived(true);
System.out.println("Chart data is Now Available");
} else {
System.out.println("Server has no data");
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}

return;
}
}
}

}


}

// END ZAHID




}
Md Zahid Nasim

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Thu Jun 05, 2008 4:29 pm

surely you need to include the jar file that contains CCTools in the archive tag

znasim
Posts: 10
Joined: Wed Feb 20, 2008 7:06 am

ClassNotFoundException

Post by znasim » Fri Jun 06, 2008 6:06 am

I am already included jar archive into applet tag. Please give me another solution
Md Zahid Nasim

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Applet ClassNotFoundException and AppletClassLoader erro

Post by david.gilbert » Fri Jun 06, 2008 7:39 am

This isn't a JFreeChart issue, it is an applet/classpath issue. Still, if you want someone in this forum to post a solution then you'll have to (at least) post the right information.
znasim wrote:<applet code="CCTools.WebChart.class" archive="jcommon-1.0.10.jar,jfreechart-1.0.6.jar" width=400 height=400>
</applet>
As 'skunk' correctly pointed out, the above applet tag isn't going to work, because the JVM isn't going to be able to find your CCTools.WebChart class.

Now you say you *do* have the relevant jar in your archive tag - so why not post the tag that you are now using, instead of the one above which clearly won't work.

I don't know if it will help you, but here is an applet tag for an old applet I wrote that I know is working:

Code: Select all

<APPLET ARCHIVE="jfreechart-1.0.5-applet-demo.jar,jfreechart-1.0.5.jar,jcommon-1.0.9.jar" CODE="demo.applet.Applet1" width="520" height="260" ALT="You should see an applet, not this text.">

                  </APPLET>
The first jar file in that list contains the class demo.applet.Applet1. The next two jars are the standard JFreeChart and JCommon jars.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked