Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lourdes Edwards   on Oct 14 In Java Category.

  
Question Answered By: Alexander Bouchard   on Oct 14

Now, i only use applet  instead of Swing and i reach pictures using URL
class.
But, the main  idea of my project is to create  an "OwnItemClass".
Some instances  of my "OwnItemClass" will be created.
I try this :


//Calling function
public class  myMenu extends Applet {
img tom;
Image t;
public myMenu() {
}
public void  init() {
tom=new img();
tom.init();
t=tom.ownItem();// ownItem() should return an Image object i would paint
in a paint function

}
//here would be paint function...
}


class img extends Applet {
URL url = null;
Image C3;

public Image ownItem() {

try {
url = new URL(getDocumentBase(),"../img/hautG.gif");
}
catch(MalformedURLException malformedurlexception) {}
C3 = getImage(url);
return C3;
}

}

It doesn't work.
I made some debugging seachs and i see that getDocumentBase, in this class
was certainly unknown.
The exact error is a null pointer return:

java.lang.NullPointerException
at java.applet.Applet.getDocumentBase(Applet.java:95)
at javamenu.img.ownItem(myMenu.java:32)
at javamenu.myMenu.init(myMenu.java:17)
at com.borland.jbuilder.runtime.applet.AppletTestbed.startApplet(Unknown
Source)
at com.borland.jbuilder.runtime.applet.AppletTestbed.main(Unknown Source)

What could i do in order to succeed in creating my own class
N.B : I already this kind of work  in javascript
(http://gmanouvrier.free.fr/cuisines)
I would change my java  script menu  into a good own java menu.

Share: 

 

This Question has 7 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on My first Applet have a problem Or get search suggestion and latest updates.


Tagged: