mirkazemisaman
11-28-2003, 07:38 PM
Alright, I am quiet a novice in java programming. I tried to search on google for source code to upload images and tried them. But I am still getting errors when trying to run my program. So as a last resort I came here to ask you guys since I know I can always get solutions here...
Here is my sample code (sorry, for some reason the message board takes out my bracket indentations):
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.Toolkit.*;
public class TestImage extends JFrame
{
private Image picture;
private Graphics gfx;
private Toolkit toolkit = Toolkit.getDefaultToolkit();
public TestImage()
{
picture = toolkit.getImage("fivecards.gif");
gfx = this.getGraphics();
gfx.drawImage(picture, 0, 0, this);
this.setSize(500, 500);
this.show();
}
public static void main(String [] args)
{
TestImage window = new TestImage();
}
}
The image is in the same directory as the file and the code compiles, but i get a run-time error (NullPointerException in "main") at lines 15 and 21 (1st line is the 1st import statement). Can someone enlighten me as to what I am doing wrong????
thanx in advance.
Here is my sample code (sorry, for some reason the message board takes out my bracket indentations):
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.Toolkit.*;
public class TestImage extends JFrame
{
private Image picture;
private Graphics gfx;
private Toolkit toolkit = Toolkit.getDefaultToolkit();
public TestImage()
{
picture = toolkit.getImage("fivecards.gif");
gfx = this.getGraphics();
gfx.drawImage(picture, 0, 0, this);
this.setSize(500, 500);
this.show();
}
public static void main(String [] args)
{
TestImage window = new TestImage();
}
}
The image is in the same directory as the file and the code compiles, but i get a run-time error (NullPointerException in "main") at lines 15 and 21 (1st line is the 1st import statement). Can someone enlighten me as to what I am doing wrong????
thanx in advance.