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 8, 2009 8:01 PM in response to phidelity1

could you kindly outline how you are running this program in the browser?


i cannot get the desired/expected output on my tower or my laptop

i have done a bout of system maintenance - fixed permissions which is now crashing safari the message in the crash report says
Process: Safari [249]
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 [113]

Interval Since Last Report: 132 sec
Crashes Since Last Report: 2
Per-App Interval Since Last Report: 94 sec
Per-App Crashes Since Last Report: 1

Date/Time: 2009-11-08 19:51:19.821 -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 8, 2009 8:05 PM in response to phidelity1

I am on 10.5.8 and I clicked "Restore Defaults" which switched me to 32-bit 5.0. Before I tested your program I tried a simple Hello World applet and I couldn't even get that to run in 6.0.

I just tested it with 32-bit (my max on that machine) 6.0 from 10.6 and 64-bit 6.0 from 10.5.8 and it works fine now. My problem was when I compiled it. If you are using the Java 6.0, you must give it "-target 5" in order to make it work on either Java 5.0 or Java 6.0. Perhaps that is the problem you are having.

Perhaps someone else knows the reason for this. I'm no Java expert, even though I run it on a regular basis - once a year - whether I need to or not. At least I'm good for another year now.

Nov 8, 2009 8:22 PM in response to etresoft

here is the java console output when i attemp to run this in firefox

if anyone can help shed some light it would be most appreciated.

BTW etresoft i really appreciate the information and aid

thanks



Java Plug-in 1.5.0
Using JRE version 1.5.0_20 Java HotSpot(TM) Client VM
User home directory = /Users/rafe


----------------------------------------------------
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 @ Sun Nov 08 20:16:12 PST 2009]
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)

Nov 9, 2009 10:10 AM in response to etresoft

where do i key in the "-target 5" command so it is directed at the Javac? and is that the full key sequence?

as i mentioned i am a newbie, my first programming course, and the course supports windows so the text and support materials are all geared for navigation in a windows environment. i have only found limited information on the apple website. nothing in terms of tutorials about java in mac.

yes i have been using the editor as a crutch in the short term until i can gain knowledge of the mac integration - that will change

thanks again for sharing your knowledge

Nov 9, 2009 11:08 AM in response to phidelity1

phidelity1 wrote:
where do i key in the "-target 5" command so it is directed at the Javac? and is that the full key sequence?


On the command line. Type in "javac -target 5 Yourfile.java"

as i mentioned i am a newbie, my first programming course, and the course supports windows so the text and support materials are all geared for navigation in a windows environment.


Bummer.

i have only found limited information on the apple website. nothing in terms of tutorials about java in mac.


It is true that Java isn't very big on the Mac. Cocoa is so much easier and people who prefer tools other than Cocoa probably don't like Java either. Look for tutorials about Java on Linux or Solaris (should be plenty of that). There are differences between Linux, Solaris, and MacOS X - but not in Java.

yes i have been using the editor as a crutch in the short term until i can gain knowledge of the mac integration - that will change


I can't help you with TextMate or Blue J. Compiling with some editor is usually just a fancy trick that no one outside of emacs ever uses. Use the command line.

Nov 9, 2009 11:39 AM in response to etresoft

Hello etresoft

so this is how my day is going! safari keeps crashing and i received the message that the crash is due to the javaPlugginCocoa.bundle which means i have to disable that pluggin to keep safari from crashing and it is necessary to run the java applet. which apple tells me i need to do an archive and reinstall to correct the problems
Argh!!

so i tried your command from the terminal window on my MBP with the applet located in a folder on the desktop to which i get the response

unrecognized option: -
could not create the java virtual machine

???

so stuck today damm

Nov 9, 2009 11:58 AM in response to phidelity1

phidelity1 wrote:
so this is how my day is going! safari keeps crashing and i received the message that the crash is due to the javaPlugginCocoa.bundle which means i have to disable that pluggin to keep safari from crashing and it is necessary to run the java applet. which apple tells me i need to do an archive and reinstall to correct the problems


It sounds like good advice. Do you really have 10.5.6? Maybe you need to update your system software. Until then, you can always use Firefox.

so i tried your command from the terminal window on my MBP with the applet located in a folder on the desktop to which i get the response

unrecognized option: -
could not create the java virtual machine


What Java versions do you have installed? Can you paste the exact command you are entering?

Nov 9, 2009 12:25 PM in response to etresoft

java - target 5 DoiliesApplet.java

returns the message

Unrecognized option: -
Could not create the Java virtual machine.


part 2 my macbook pro is on 10.5.6 and safari 3.??

mac pro is on 10.5.8 safari 4.03

the java version i have installed that show up in the java preference window are

j2se 1.4.2 32 bit version
j2se 5.0 32 bit
j2se 5.0 64 bit
j2se 6.0 64 bit

i have both listed in the applications and applet sections of the preferences page

Nov 9, 2009 12:46 PM in response to phidelity1

phidelity1 wrote:
java - target 5 DoiliesApplet.java


First of all, you need to compile your Java source into bytecode. Use "javac". The "java" command is only to run a compiled Java application.

You have a space between "-" and "target". It should be "-target" with no space.

mac pro is on 10.5.8 safari 4.03


That looks good.

the java version i have installed that show up in the java preference window are

j2se 1.4.2 32 bit version
j2se 5.0 32 bit
j2se 5.0 64 bit
j2se 6.0 64 bit


What happens when you click the "Restore Defaults" button for both?

Regardless, it should look like this on your machine for both applications and applets
j2se 5.0 32 bit
j2se 6.0 64 bit
j2se 5.0 64 bit
j2se 1.4.2 32 bit version

That should help matters quite a bit.

Nov 9, 2009 1:19 PM in response to etresoft

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

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

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

let me also wind back. originally my problem was the when i compiled the applet within the ide it would allow me three options for output !

1 Generate Web page Only - generates/saves an html document which will run but the graphics and text will not display in the browser. the title of the web page is returned in the browser window pain along with an x. this is different now because the Java.pluggin.cocoa.bundle had to be removed from the system> library>internetpluggins folder - literaly placed in the disabled pluggins folder so safari would stop crashing

2 Open in applet viewer - which compiles and runs as expected in the editors own applet viewer

3 Run applet in web browser - same results as # 1

i have changed the java preferences - tried restoring defaults etc

the crashing of safari started happening last evening after i noticed there were javForMacUPdate2 and 3 which i ran (foolishly) update 3 said i did not require it since then my minor programming java issue has gotten worse.

just to be clear on my Mbp running 10.5.6 the same java sdk without the updates and on safari 3.? i have the same return issues when i run the saved html document.

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.