Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 33

Thread: putting java class online

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default putting java class online

    i created a game in applet and i want to put it on a site. the problem is that my games has alot of classes. how can i use applet tag to up it online?



    java.php


    <html>
    ...
    <applet code = "Main.class" width = 900 height = 400> </applet>	
    ...
    </html>



    my folder tree


    -java_game
         -java.php
         -main.class
         -item.class 
         -background.clas
         -enemy.class
          -...
         -music
                -...
         -image
                 -...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    my games has alot of classes
    Put the classes into a jar file and add an archive= attribute to the <applet tag in the html
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i just have about 10 files inside my java project. not dont have package. do i have to make a package to create all thoses jar files??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    do i have to make a package to create all thoses jar files??
    No, you don't need to put the classes in packages.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i am confuse
    Put the classes into a jar file and add an archive= attribute to the <applet tag in the html
    i though i cant make applet into jar files?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    You can put any files into a jar file.

    What is done with that jar file depends on what program is reading it.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    ....so let me try again
    here is my folder. it has all my java class and images and sounds.
    asdf.jpg


    in my java_game_2.php
    i am using this tag. now if it was only one file than it works fine with this tag.
    <applet code = "Main.class" width = 900 height = 400> </applet>

    porblem is that i have more than one files. and when i run in web, it give me error i looked online but i could only file this example. can u plz help me to fix this problem?



    error on web:
    Java Plug-in 1.6.0_29
    Using JRE version 1.6.0_29-b11 Java HotSpot(TM) Client VM
    User home directory = C:\Users\dave
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------


    java.lang.UnsupportedClassVersionError: Main : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.UnsupportedClassVersionError: Main : Unsupported major.minor version 51.0

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Put all the files used by the program into the jar file as said in post#2


    Unsupported major.minor version 51.0
    That says the class file was created by a newer version of java (1.7) than the version of java being used to execute the code: Java Plug-in 1.6.0_29.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i dont now how to put them in jar files. i was trying to put them in jar files in last post. but than u said something about Applets are not executed with the java command.

    --- Update ---

    so i need to download newversion of web java?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    The java command requires that the class it starts executing have a main() method.
    Applets do not use a main() method.

    Read the tutorial that I have given you several links to. It's explained there.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i asked do i need to download new version of java?

    i already now applet dont have main method.

  12. #12
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i asked do i need to download new version of java?

    i already now applet dont have main method.

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    The version of java that executes the class file must be compatible with the version of the JDK that created the class file. The new version of java JDK: 1.7 is NOT compatible with the older versions of java.
    The javac command has options for creating class files that are compatible with older versions of java.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    just download new version of java. and errors are gone. but animation isnt moving and cant see my player. is this bc of not having jar file?

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Are there any error messages?
    Locally executing a class from a jar file or from a disk file should not make any difference.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    no erros

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Try debugging the code by adding some println statements to print out messages showing execution flow and the values of variables as the code executes. The print out will help you see what the computer is doing when it executes your code.
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    ah now its give me this error: any idea? i have the new version

    Java Plug-in 10.17.2.02
    Using JRE version 1.7.0_17-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Users\dave
    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
    at Main.paint(Main.java:206)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
    at Main.paint(Main.java:206)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
    at Main.paint(Main.java:207)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    Main.java
    line205: public void paint(Graphics g) {
    line206: background_class.paint(g, this);
    line207: ground_class.paint(g);

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
    at Main.paint(Main.java:206)
    There is a variable with a null value when line 206 is executed. Look at line 206, find the variable with the null value and find out why it has a null value.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    i dont understand why in eclipse it have no error in Main.class but on web it gives me error.

    great now new error:
    Java Plug-in 10.17.2.02
    Using JRE version 1.7.0_17-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Users\dave
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Main.class]: updateAvailable=true,lastModified=Sat Nov 24 22:20:05 EST 2012,length=6998
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Enemy.class]: updateAvailable=true,lastModified=Sat Nov 10 10:28:15 EST 2012,length=2340
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Enemy_1.class]: updateAvailable=true,lastModified=Sat Nov 10 10:28:48 EST 2012,length=1834
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Platform.class]: updateAvailable=true,lastModified=Sat Nov 10 10:26:29 EST 2012,length=2535
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Item.class]: updateAvailable=true,lastModified=Sat Nov 10 10:26:41 EST 2012,length=1757
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Sprite_Sheet.class]: updateAvailable=true,lastModified=Sat Nov 10 07:29:27 EST 2012,length=1603
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Background.class]: updateAvailable=true,lastModified=Sat Nov 10 10:30:05 EST 2012,length=1535
    Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
    	at Main.paint(Main.java:204)
    	at sun.awt.RepaintArea.paintComponent(Unknown Source)
    	at sun.awt.RepaintArea.paint(Unknown Source)
    	at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    CacheEntry[http://localhost/E_COMMERCE/menu_pages/game_pages/java_game_2/Ground.class]: updateAvailable=true,lastModified=Sat Nov 10 10:28:04 EST 2012,length=2312


           /*** paint method ***/
    	@Override
    	public void paint(Graphics g) 
    	{
    		background_class.paint(g, this);	              //line204
    		ground_class.paint(g);                              //line205
    	                                                                       //line 206
    		player_class.paint(g);            
    		for(int i = 0; i < platform_class.length; i++)
    		{ platform_class[i].paint(g); }
    		shoot_class.paint(g, player_class); //draw bullet
     
     
    				enemy_class.paint(g, enemy_class);
     
    		for(int i = 0; i < item_class.length; i++)
    		{ item_class[i].paint(g); }
    		score_class.paint(g, this, player_class);
     
    	}/*** end of paint method ***/

    the line look fine to me.

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    What variable has the null value? If you don't know, add a println() statement to print out the values of all the variables.

    Where is that variable assigned a value?
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    on line 204: i printed the value of 'this'
    Main[panel0,0,0,900x400,layout=java.awt.FlowLayout]
    on line 204: i printed the value of 'g'
    sun.java2d.SunGraphics2D[font=java.awt.Font[family=Serif,name=Serif,style=bold,size=20],color=java.awt.Color[r=15,g=77,b=147]]
    on line 204: i printed the value of 'background_class'
    Background@31908ba7
    they all have some values

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Did the program get the exception immediately after those println()s were executed?

    Keep adding println() statements to show the variables used on each line until you see the variable that is null.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #24
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: putting java class online

    yes and printed the value right after the line 204

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: putting java class online

    Did the program get the exception immediately after those println()s were executed?

    Keep adding println() statements to show the variables used on each line until you see the variable that is null.

    Copy and post the whole contents showing the print outs and the exception error message
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. About Java online course
    By geek101 in forum The Cafe
    Replies: 3
    Last Post: October 3rd, 2012, 12:06 PM
  2. Which is the best place to get java tutorial online??
    By texsas12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 2nd, 2012, 07:45 PM
  3. Java Online Compiler
    By sb24 in forum Java Theory & Questions
    Replies: 15
    Last Post: March 23rd, 2012, 09:50 AM
  4. [SOLVED] Putting Trajectory of a Projectile formula in Java form.
    By mwebb in forum Java Theory & Questions
    Replies: 2
    Last Post: March 2nd, 2012, 07:23 PM
  5. online system on java
    By u-khan1 in forum Paid Java Projects
    Replies: 0
    Last Post: March 8th, 2011, 06:02 AM