Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Applet not execute external class code

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I am jsut starting out with java so please pardong any ignorence on my part.

I have create a java class that reads weatherundergrounds xml feed (using nu.xom) and then creating a seperate java applet reference this class. Using the Java Tester this all works great. But I can not get the applet to work in my browser (chrome or ie). Once I make my call to my external call, the applet stops displaying whats next.

My applet lives in the same folder as the external class. Since the broswer can start to show the applet I assume it should be able to find the external class. Also I DO NOT get any error when viewing the applet in the browser.

I can post code, but I thought I would save time and space in this thread if the problem was somethign common and I just do not know about it. If you do need to see the code, let mek now.

Thanks,
RalphTrent
 
How are you testing the applet? Can you see anything in the Java console?

Cheers,
Dian
 
I am developing in NetBeans 6.8 and using the built-in applet tester. The tester shows EXACTLY what I want to show, but when I include the applet in HTML it does not. Do I need to also reference the external classes in HTML somehow. I am only referencing the applet class.
 
External classes use to be referenced with the ARCHIVE parameter. Take a look at this

Cheers,
Dian
 
When you say "use to be" does that mean they no longer need to be? I create a jar file and set the path/jar file name to the value of Archive, but I still get the same issue.
here is my applet html code
Code:
<applet code="WeatherForcast.class"
        archive="..\\dist\\WeatherForcast.jar"
              width="400" height="275"
              style="border:1px solid black">
     <param name="zipCode" value="12345">
</applet>

here is a portion of my applets pain code
Code:
String zipCode = "07027"; //getParameter("zipCode");
String title = "Weather conditions for " + zipCode;
int titleLeft = (this.getWidth() / 4)- title.length() / 2;
screen2d.drawString(title, titleLeft, 20);
try {
 ws = new WeatherUnderground();
 Object[][] dailyWeather = ws.getWeather(zipCode);
WeatherUnderground is the different class file. The only thing my applet shows is my title.

I can't image the code itself is bad since the applet tester works fine, I think it is a reference issue, but i have not clue. I looked at the link you provided, but I still do not understand

Do I need to make reference to the code element? How do I find that in NetBeans. I know in eclipse I can manually enter a code name when I create the project but I do not see how in NetBeans.

Thanks,
RalphTrent
 
thats just the thing, there is no error. The applet never loads completely. the prints out the Title and then nothing else happens. When I run this applet in NetBeans it works fine, it just when I try to view it in the web browser it does not. Its very strange.
 
OK Now we are getting some where.

here is the exceptions I am seeing (over and over again):

Exception in thread "AWT-EventQueue-8" java.lang.NoClassDefFoundError: nu/xom/Builder

nu/xom/builder is imported in my external class.
The stack shows it getting to my external class, but for some reason I still get this message. Im sure you already know that nu/xom is a library I downloaded online and included in my project. What do I need to do to include the reference or the library to my applet for web use?

Thanks,
RalphTrent
 
I had no idea about what nu/xom was, but anyway, you need to include the jar of that library in the archive field

Cheers,
Dian
 
nu/xom is an XML Library. I read about it in a java book I am using to learn Java with. (Java in 24 hours). I come from a c# world so when you compile in Visual Studio, all reference objects are gathered for you. I assume Java is not like that when you create a jar file? If I have created a jar file for a program referencing an external libirary, I need to explicitly create a jar for that library?

I do get this message when I go to compile my jar file:
Code:
F:\java\libraries\XOM is a directory or can't be read. Not copying the libraries.
Building jar: F:\java\NetBeansProjects\WeatherForcast\dist\WeatherForcast.jar
Not copying the libraries.

I recreate the libirary pointing to the the zip file of the library and not the extracted folder. I then no longer got that message upon complining and the applet now works with out changing my html. The applet is slow to load in the browser as oppsed to the applet tester in net beans. Are there any configurations i need to set in my HTML to have this applet load faster?

Is there a built in XML parser in Java?

Thanks again.
 
Well Java doesn't specify the content of a jar file. I don't know NetBeans, but in Eclipse you can choose which of the referenced libraries are exported when you create a jar file.

I don't know of any magical configuration that will make it faster. How big is the jar file?

Yes, Java has a built-in XML parser: javax.xml.parsers

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top