File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need help >>> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need help >>>" Watch "Need help >>>" New topic
Author

Need help >>>

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi ppl,
I have taken this prog. from a ref. book. this prog. compiles OK but as the Applet is coming up on the screen it says(in the lower most line) of the appletviewer..Applet not initialised..
Same problem when I run it on the Netscape Browser...in that case it says "Applet cant start :ERROR".
Dont forget to see the error that pops on the DOSpromot
HELP SOON....EXAM VERY CLOSE AND JUST A BEGINNER........
import java.awt.*;
import java.applet.*;
import java.lang.*;

public class BarChart extends Applet
{
String laabel[];
int n = 0;
int value[];
public void init()
{
try
{
n = Integer.parseInt(getParameter("columns"));
laabel[0] = getParameter("Label1");
laabel[1] = getParameter("Label2");
laabel[2] = getParameter("Label3");
laabel[3] = getParameter("Label4");
value[0] = Integer.parseInt(getParameter("c1"));
value[1] = Integer.parseInt(getParameter("c2"));
value[2] = Integer.parseInt(getParameter("c3"));
value[3] = Integer.parseInt(getParameter("c4"));
}
catch (NumberFormatException e) {}
}

public void paint(Graphics g)
{
for(int i = 0; i<n ; i++)>
{
g.fillRect(50,i*20 + 10,value[i],20);
g.drawString(laabel[i], 20, i*30 + 10);
}
}
}
/*
<HTML>
<HEAD>
</HEAD>
<BODY>
<APPLET>
CODE = BarChart.class
WIDTH = 100
HEIGHT =300>
<PARAM NAME = "columns" VALUE = "4">
<PARAM NAME = "Label1" VALUE = "90">
<PARAM NAME = "Label2" VALUE = "91">
<PARAM NAME = "Label3" VALUE = "92">
<PARAM NAME = "Label4" VALUE = "94">
<PARAM NAME = "c1" VALUE = "110">
<PARAM NAME = "c2" VALUE = "200">
<PARAM NAME = "c3" VALUE = "50">
<PARAM NAME = "c4" VALUE = "80">
</APPLET>
</BODY>
</HTML>
*/
//this is the error in DOS Prompt
java.lang.NullPointerException:
at BarChart.init(BarChart.java:19)
at sun.applet.AppletPanel.run(Compiled
at java.lang.Thread.run(Thread.java:47
Suresh
Ranch Hand

Joined: May 08, 2000
Posts: 76
jdummy,

String laabel[];
......
laabel[0] = getParameter("Label1");
laabel[1] = getParameter("Label2");
laabel[2] = getParameter("Label3");
laabel[3] = getParameter("Label4");

See, you have just declared the String array, but you haven't constructed it!!
Change that line to
String laabel[] = new String[4];
The same problem will crop up for your value array also. Change that to
int value[] = new int[4];
Regards,
Suresh.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
thx Suresh,
JDummy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help >>>