newbie java programming applet issue

hello

i am a student taking an intro to OOP course using java- the course only offers support for windows. i have textMate and blue J as java editing environments. i have successfully managed a few lessons but now i am having trouble with applets. my applet source code will run in blue j but not in textmate and i think the reason has to do with the applet extension. first when i run the program successfully in blue jay it utilizes the sun.applet.main environment to display the applets output. but in textmate the identical code generates an error which i finally have a some information about why?

the error in textmate reads

:exception in thread "main" java.lang.NoSuchMethodError: main

i am not sure whether this has to do with the import java.awt.*: or just the public void paint(Graphics g) method (code Below)

the eventual intended output of the applet is to a web browser via an html document which calls the java applet but when i run this html document both firefox and safari display blank pages.

i am on macpro with the latest java version - just downloaded last week

is there some unique import statement to utilize import java.awt.*;
import java.applet.*; in mac os or ???

BTW the smile.gif is in the project folder with the java document

thanks for any help
/*
Chapter 2: Welcome to My Day
Programmer: rafe McDonald
Date: November 5, 2009
Filename: WelcomeApplet
Purpose: This project displays a smile graphic, welcome message, the user's
name, and the system date in an applet.
*/

import java.util.Date;
import java.awt.*;
import java.applet.*;

public class WelcomeApplet extends Applet
{
public void paint(Graphics g)
{
Date currentDate = new Date(); //Date constructor
g.drawString("Welcome to my day!",200,70);
g.drawString("Daily planner for Rafe McDonald",200,100);
g.drawString(currentDate.toString(),200,130);
Image smile; //declare an Image object
smile = getImage(getDocumentBase(), "smile.gif");
g.drawImage(smile,10,10,this);
setBackground(Color.cyan);
}
}

macpro 2x 2.8 quad xeon Mac OS X (10.5.8)

mbp 2.5, Mac OS X (10.5.6)

Posted on Nov 8, 2009 5:06 PM

Reply
21 replies

Nov 9, 2009 1:44 PM in response to phidelity1

phidelity1 wrote:
i have used the restore defaults command - no luck, same results- i tied this when you first advised me.


Then manually rearrange your Java environments (both sets) to match the order I listed above.

where do i find javac? - i have searched using spotlight and manually


It should be in /usr/bin

i will need to run this on the MBP because the java.pluggin.bundle will crash safari.


I think that if you fix your Java runtime version so that version 5.0 is on top you won't get that crash anymore.

After you get your Java versions in the correct order, you will have to recompile your applet. If you are using Java version 6, you must use "-target 5". If you are using Java version 5, you don't have to do anything extra.

Test in Firefox if you can't get Safari to run. But I think once your Java versions are correct, you can put the plugin back where it came from.

Nov 9, 2009 4:58 PM in response to phidelity1

when i try to run the java in firefox i receive the following exception and i have manually reset the order in the java preferences

Java Plug-in 1.5.0
Using JRE version 1.5.0_20 Java HotSpot(TM) Client VM
User home directory = /Users/rafe
network: Loading user-defined proxy configuration…
network: Done.
network: Loading proxy configuration from Netscape Navigator…
network: Done.
network: Loading direct proxy configuration…
network: Done.
network: Proxy Configuration: No proxy

basic: Cache is enabled
basic: Location: /Users/rafe/Library/Caches/Java/cache/javapi/v1.0
basic: Maximum size: unlimited
basic: Compression level: 0

----------------------------------------------------
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
p: reload proxy configuration
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>
----------------------------------------------------

MRJ Plugin for Mac OS X v1.0.1
[starting up Java Applet Security @ Mon Nov 09 16:55:38 PST 2009]
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@ce85c4, refcount=1
basic: Loading applet…
basic: Added progress listener: sun.plugin.util.GrayBoxPainter@78aa80
basic: Initializing applet…
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@ce85c4, refcount=2
basic: Releasing classloader: sun.plugin.ClassLoaderInfo@ce85c4, refcount=1
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:172)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:687)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:723)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1870)
at jep.AppletFramePanel.createApplet(AppletFramePanel.java:189)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:652)
at sun.applet.AppletPanel.run(AppletPanel.java:326)
at jep.AppletFramePanel.run(AppletFramePanel.java:176)
at java.lang.Thread.run(Thread.java:613)
basic: Exception: java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:172)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:144)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:687)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:723)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1870)
at jep.AppletFramePanel.createApplet(AppletFramePanel.java:189)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:652)
at sun.applet.AppletPanel.run(AppletPanel.java:326)
at jep.AppletFramePanel.run(AppletFramePanel.java:176)
at java.lang.Thread.run(Thread.java:613)



this is the crash report from safari. as soon as i return the javapluggin.cocoa.bundle in the internet pluggins folder safari crashes

Process: Safari [3100]
Path: /Applications/Safari.app/Contents/MacOS/Safari
Identifier: com.apple.Safari
Version: 4.0.3 (5531.9)
Build Info: WebBrowser-55310900~1
Code Type: X86 (Native)
Parent Process: launchd [117]

Interval Since Last Report: 42370 sec
Crashes Since Last Report: 6
Per-App Interval Since Last Report: 42694 sec
Per-App Crashes Since Last Report: 5

Date/Time: 2009-11-09 16:30:09.656 -0800
OS Version: Mac OS X 10.5.8 (9L30)
Report Version: 6
Anonymous UUID: 9CCA1AB6-7069-48E4-A80E-1F8F7FFD9CA6

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0

Dyld Error Message:
Symbol not found: _JVMGetJVMsWithCurrentArchitectureForTask
Referenced from: /Library/Internet Plug-Ins/JavaPluginCocoa.bundle/Contents/MacOS/JavaPluginCocoa
Expected in: /System/Library/Frameworks/JavaVM.framework/Versions/A/JavaVM

Nov 10, 2009 2:12 PM in response to etresoft

hi etresoft

i have tried rebuilding the package with no luck.

i retried your command line tactic but i moved the java file to my root directory which gave me a different error

"rafePro:~ rafe$ javac -target 5 DoiliesApplet.java
error: cannot read: DoiliesApplet.java
1 error
rafePro:~ rafe$ "

i have also posted to the Blue J users forum which i got a response that confirms your suspicion which is the issue is version compatiblity because Blue J has defaulted to using the newer install of java.

the user there suggested the opposite tactic of placing the newest version in the 1st option in the java preferences and restarting the browser so it would lock on to that version and hopefully run the program. no luck with this tactic. but it did stop safari 4.03 from crashing!

so i now have a support request placed with Blue J. i will post here if i get it sorted.

thanks again for all your time and expertise. i was helpful in the very least at getting me clearer on the issue

regards

rafe

Nov 10, 2009 4:16 PM in response to phidelity1

phidelity1 wrote:
i retried your command line tactic but i moved the java file to my root directory which gave me a different error

"rafePro:~ rafe$ javac -target 5 DoiliesApplet.java
error: cannot read: DoiliesApplet.java
1 error
rafePro:~ rafe$ "


Root directory? That looks like your home directory. You can put the .java file anywhere you want, but the class file needs to be in some directory in the "Sites" folder in your home directory so you can easily test it. I created an "applet" directory containing the java, class, and html files. Then I could just access http://localhost/~jdaniel/applet/Hello.html to test.

That is the correct command, but I don't know what is going on with "cannot read".

Nov 11, 2009 12:19 PM in response to etresoft

hello Etresoft

So Mate here is the sollution!!

for some reason blue j is not seeing the java preferences so i had to use a similar "target command" within there BlueJ.def file that is stored in the application contents. once i altered that line of code, rebooted and recompiled the applet it worked as expected.

so thanks for your efforts

and here is a handy link that verifies the version of java that is installed and active on your machine:

http://www.javatester.org/version.html

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

newbie java programming applet issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.