Results 1 to 10 of 10
Like Tree3Likes
  • 1 Post By Tolls
  • 1 Post By Norm
  • 1 Post By Maarten

Thread: Program does not work if I put it online

  1. #1
    Maarten is offline Member
    Join Date
    Dec 2011
    Location
    Utrecht
    Posts
    24
    Rep Power
    0

    Default Program does not work if I put it online

    Hello,
    I wrote a program which runs fine in my editor but not if I put it online.
    I simplified it as much as possible and this is what is left and it still gives an error (incompatible magic value in class file Kaartspel):

    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    
    public class blackjack6 extends Applet {
      
      
      private Kaartspel Stapel;
      
      
      public void init() {
        
        Stapel = new Kaartspel();
        
      }
      
      public void paint (Graphics g) {
        
        Stapel.laatZien(g);
      }
      
    }
    
      class Kaartspel{
      
        public void laatZien (Graphics g) {
          g.drawString("Jahallo",100,130);
          }
    
    }
    The URL where I uploaded is: [Moderator edit: irrelevant link removed]

    Anybody an idea why it doesn't run when I put it online?
    Last edited by DarrylBurke; 08-02-2012 at 11:01 AM. Reason: Removed spammy link

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Program does not work if I put it online

    If you are still stuck and need help, please show the full and exact error message, including any line numbers that may be present, and then indicate which lines in your code corresponds to the line numbers in the error messages.

  3. #3
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default Re: Program does not work if I put it online

    Hello Maarten,

    Nice that you made a SSCCE (small self contained compiling example).
    I don't immediately see the reason for failing, but a few points to improve:
    At first, there is a naming convention, and Classnames are supposed to start with a capital letter: so "BlackJack". You did it correct with "Kaartspel". And variables like "Stapel" should be written in lower-case letters.

    Second, you are using AWT. That is very outdated and it is better to avoid it and use Swing; see for instance Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials).

    Most of the times something runs on your computer but not on the site, the reason is that you make some case-error. Most servers run unix and are case-sensitive, windows is not.
    I see no mistakes, but I see that you deployed it as a jar: 'blackjack6.jar'. Are you sure that the filename is written with the same capitalization as in you applet-tag?

    The "incompatible magic value in class file Kaartspel" hints on the server not recognizing your classfile, but that is wisdom I got from google, not my own experience. Try google to find out for yourself.
    No bug ever had to calculate its fitnessfunction.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Program does not work if I put it online

    "incompatible magic value in class file Kaartspel" means you compiled your code in a later version of Java than the one you are running it on in the browser.
    Fubarable likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Program does not work if I put it online

    (incompatible magic value in class file Kaartspel):
    Can you post the full test of the error message. It has valuable info about the problem.
    You can get that error with a corrupted .class file when the first 4 bytes of the class file does not contain: 0xcafebabe

    The newer/older versions of java problem gives this error:
    Unsupported major.minor version 51.0
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Program does not work if I put it online

    Quote Originally Posted by Norm View Post
    You can get that error with a corrupted .class file when the first 4 bytes of the class file does not contain: 0xcafebabe
    That's curious...

    Edit: Interesting:
    "The first four bytes of every class file are always 0xCAFEBABE. This magic number makes Java class files easier to identify, because the odds are slim that non-class files would start with the same initial four bytes. The number is called magic because it can be pulled out of a hat by the file format designers. The only requirement is that it is not already being used by another file format that may be encountered in the real world. According to Patrick Naughton, a key member of the original Java team, the magic number was chosen "long before the name Java was ever uttered in reference to this language. We were looking for something fun, unique, and easy to remember. It is only a coincidence that OxCAFEBABE, an oblique reference to the cute baristas at Peet's Coffee, was foreshadowing for the name Java."
    Source: JavaWorld
    Last edited by awinston; 08-02-2012 at 04:37 PM. Reason: Additional Info
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default Re: Program does not work if I put it online

    Easy to test. Rename any non-class to have a .class extension and try to execute the file. Here I renamed ATestFile.txt file to be a .class file and tried to execute it:

    C:\Testing>java.exe ATestFile
    Exception in thread "main" java.lang.ClassFormatError: Incompatible magic value 1416128883 in class file ATestFile
    awinston likes this.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Program does not work if I put it online

    I just thought that the choice of the magic number was a bit strange
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Program does not work if I put it online

    Quote Originally Posted by Norm View Post
    The newer/older versions of java problem gives this error:
    Unsupported major.minor version 51.0
    Gah, yes...!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Maarten is offline Member
    Join Date
    Dec 2011
    Location
    Utrecht
    Posts
    24
    Rep Power
    0

    Default Re: Program does not work if I put it online

    Thanks for all your replies. I found my mistake.
    I did not realize that when I compiled my applet, a .class file for every class was created.. I thougt only the .java file became a .class file.
    So when I put BlackJack6.class and Kaartspel.class in the same jar file it worked! Found it by trying out all the suggestions.
    thanks, Maarten.
    Fubarable likes this.

Similar Threads

  1. program compiles but does not work
    By alara in forum New To Java
    Replies: 4
    Last Post: 11-27-2011, 08:47 PM
  2. Trying to work out this program
    By KidneyinaCooler in forum New To Java
    Replies: 6
    Last Post: 07-18-2010, 03:14 AM
  3. Program don't work
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-04-2007, 09:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •