• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

2 problems

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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();
 
The moustache of a titan! The ad of a flea:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic