File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes NUllPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NUllPointerException" Watch "NUllPointerException" New topic
Author

NUllPointerException

Rajesh Chandra
Ranch Hand

Joined: Jun 13, 2005
Posts: 55
I have written a code for applet which draws a string at point x &y but it gives null Pointer Exception.can anyone help me? the code is-

import java.awt.*;
import java.applet.*;
public class SecondApplet extends Applet
{
String text;

int x;
int y;

public void init()
{
this.text= "error";
x=50;
y=100;
}
public void start(){
try{
text=getParameter(text);
}catch(Exception ex){}

try
{
x=Integer.parseInt(getParameter("x"));
y=Integer.parseInt(getParameter("y"));
}catch(NumberFormatException e){}

}

public void paint(Graphics g) throws NullPointerException
{
g.drawString("Welcome rajesh this is Applet",150,50);
g.drawString(this.text,x,y);
}
}
it is saved as SecondApplet.java and the html file is-

<HTML>

<HEAD>
<TITLE>USING APPLET TAG</TITLE>
</HEAD>
<BODY>
<H3>APPLET DISPLAYS AT X AND Y POSITION</H3>

<APPLET CODE="SecondApplet.class" WIDTH=500 HEIGHT=250>
<PARAM NAME="text" VALUE="APPLETS ARE FUN">
<PARAM NAME="x" VALUE="50">
<PARAM NAME="Y" VALUE="70">
NOT JAVA ENABLED
</APPLET>
</BODY>
</HTML>

when i use appletviewer i get a nullpointer exception.
also wen i use IE 6 as browser to open the html file the applet doesnt come.
I guess java is disabled but then how to enable it. I cant find any option in advanced tab of Internet Options.
Otherwise in appletviewer it is working fine except for nullpointer exception.Can anyone point out why the string text in g.drawString is giving the said exception? I have tried it without using "this" also.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

It would help to know what line the exception refers to. Any chance you wanted getParameter(text) to be getParameter("text") in quotes?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NUllPointerException