• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 problems

 
Chris Copeland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing my first applet (based off of a swing mini-application). I have two issues:
1. The applet works fine when I load it from File/Open in IE from my local directories it works fine, but when I put it on-line (www.umsl.edu/~crchv7/) I get the following error: java.lang.ClassFormatError: PayrollApplet (Illegal constant pool type). Why would it work one way, but fail when loading from another method?
2. Part of the application is to load a file from an input file automatically. When running as an application, I specified the file name by "./InputFile.txt". However, this doesn't seem to work for an applet. I assume this is because the class is retrieved and run in a different area (where the input file doesn't exist). How can I get it to take the file from the same directory as where the class was originating.
Thanks,
Chris copeland
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I tried the applet, and got the same error. I downloaded the .class file and tried to run "javap -c" on it, and javap reports "java.lang.ClassFormatError: invalid constant type: 0". It looks like the .class file got corrupted in the process of uploading it to the web server. You might try again or try by a different method.
2) In an applet, you can't use "new FileReader()" or anything like that (well, not unless you're using a signed applet, which is not a beginner project.) If you want the applet to read a file from the server, use a URL. Off the top of my head (this might not be precisely correct but you get the idea)
InputStream myFile = new URL(theApplet.getCodeBase(), "InputFile.txt").getInputStream();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic