views:

375

answers:

1

(Intel Mac OS 10.4.11, NetBeans IDE 6.8, SoyLatte 1.0.3)

Although I am currently taking a college course in Java and my code is based on a couple of questions from my Java textbook, I would like to make it perfectly clear that this is NOT homework. This is self-assigned for studying purposes and my professor will probably never see this, let alone grade it. Regardless, I suspect this to be a configuration-related issue as I had no such problems running this program in a Vista machine on campus. Assuming I am right, there shouldn't be any issue with any of this community's policies as I won't need to receive any "answer" code to solve this issue.

In NetBeans, my program compiles and works fine, but produces a couple of runtime errors. Any idea what could be going on here?

Here's my code:

import java.util.Scanner;       // Needed for console input.
import javax.swing.JOptionPane; // Needed for dialog boxes.

/**
   This program performs the actions requested in questions 2.35 and 2.36 in the textbook.
 * @author Dan
 */
public class Pages98To99 {
    public static void main(String[]args){

        // Asks the user for what answer he/she wants to see.
        System.out.println("Do you want to see the answer to 2.35 or 2.36?");
        Scanner keyboard = new Scanner(System.in);  // Creates a scanner object.
        double answer = keyboard.nextDouble();

        if (answer == 2.35){
            //2.35
            JOptionPane.showMessageDialog(null, "Greetings Earthling.");
            JOptionPane.showInputDialog("Enter a number.");}

        else if (answer == 2.36){
            //2.36
            String str = JOptionPane.showInputDialog("Please enter your age.");
                                                 // Gets age.
            int age = Integer.parseInt(str);}    /* Converts age from a string to an
                                                    integer.*/

        else
            JOptionPane.showMessageDialog(null, "Go to another program.");

        System.exit(0); // Ends the program


    }

}

Here are the runtime errors produced by NetBeans:

2010-02-15 21:23:54.659 java[3891] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0xf203, name = 'java.ServiceProvider' See /usr/include/servers/bootstrap_defs.h for the error codes. 2010-02-15 21:23:54.660 java[3891] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)

The following is a troubleshooting terminal session using both the newer version of JDK courtesy of SoyLatte (http://landonf.bikemonkey.org/static/soylatte/, which fails to produce a dialog box) as well as the older one supplied by Apple as part of my OS (which like in NetBeans works fine otherwise) as well.

Last login: Sat Feb 20 00:12:55 on ttyp1
Welcome to Darwin!
Dans-MacBook:~ Dan$ cd /Volumes/Lexar/NetBeansProjects/MacBook-Made/test/;echo $PATH;java -version;javac -version;javac Pages98To99.java;java Pages98To99;PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin;java -version;javac -version;javac Pages98To99.java;java Pages98To99
/sw/bin:/sw/sbin:/Applications/soylatte16-i386-1.0.3/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin
java version "1.6.0_03-p3"
Java(TM) SE Runtime Environment (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00)
Java HotSpot(TM) Server VM (build 1.6.0_03-p3-landonf_19_aug_2008_14_55-b00, mixed mode)
javac 1.6.0_03-p3
Do you want to see the answer to 2.35 or 2.36?
0
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
        at sun.awt.X11.XToolkit.(XToolkit.java:89)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at java.awt.Toolkit$2.run(Toolkit.java:836)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:828)
        at sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(SwingUtilities2.java:120)
        at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556)
        at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:130)
        at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1591)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:537)
        at javax.swing.UIManager.setLookAndFeel(UIManager.java:577)
        at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1331)
        at javax.swing.UIManager.initialize(UIManager.java:1418)
        at javax.swing.UIManager.maybeInitialize(UIManager.java:1406)
        at javax.swing.UIManager.getDefaults(UIManager.java:656)
        at javax.swing.UIManager.getString(UIManager.java:802)
        at javax.swing.UIManager.getString(UIManager.java:819)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:592)
        at Pages98To99.main(Pages98To99.java:29)
java version "1.5.0_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_19-b02-306)
Java HotSpot(TM) Client VM (build 1.5.0_19-138, mixed mode, sharing)
javac 1.5.0_19
javac: no source files
Usage: javac  
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath           Specify where to find user class files
  -cp                  Specify where to find user class files
  -sourcepath          Specify where to find input source files
  -bootclasspath       Override location of bootstrap class files
  -extdirs             Override location of installed extensions
  -endorseddirs        Override location of endorsed standards path
  -d              Specify where to place generated class files
  -encoding        Specify character encoding used by source files
  -source           Provide source compatibility with specified release
  -target           Generate class files for specific VM version
  -version                   Version information
  -help                      Print a synopsis of standard options
  -X                         Print a synopsis of nonstandard options
  -J                   Pass  directly to the runtime system

Do you want to see the answer to 2.35 or 2.36?
0
2010-02-20 00:16:09.967 java[4618] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0xf103, name = 'java.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2010-02-20 00:16:09.968 java[4618] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)
Dans-MacBook:/Volumes/Lexar/NetBeansProjects/MacBook-Made/test Dan$ 

Below is a botched attempt at getting info. from the Windows Vista environment from a computer in my Java class' lab, which compiled and ran the program flawlessly. Yeah, should've used -version. I'll update it if needed to resolve this problem.

Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Users\IRC111>java -showversion;javac -showversion
Unrecognized option: -showversion;javac
Could not create the Java virtual machine.

C:\Users\IRC111>java -showversion
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp 
    -classpath 
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D=
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:...|:]
    -enableassertions[:...|:]
                  enable assertions
    -da[:...|:]
    -disableassertions[:...|:]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:[=]
                  load native agent library , e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:[=]
                  load native agent library by full pathname
    -javaagent:[=]
                  load Java programming language agent, see java.lang.instrument

    -splash:
                  show splash screen with specified image

C:\Users\IRC111>javac -showversion
javac: invalid flag: -showversion
Usage: javac  
use -help for a list of possible options

C:\Users\IRC111>

I've done the best I could googling and searching this site in my limited time, but I've had no luck resolving this on my own. Aside from a little experience in Super User and AppleScript, I'm pretty new to both Stack Overflow and programming, so please be gentle and thanks in advanced.

+1  A: 

The first error has nothing to do with your code. It's either a Netbeans misconfiguration or an invalid setting in your project. If you compile your code on the command line with javac and run it with java you will be fine. But that doesn't answer your question. If I were you, I would try reinstalling netbeans.

The second error shows that your JVM is trying to run your code under the XWindow system. XWindow is the GUI system for linux. Fortunately there is a version available for Mac and it's available on your snow leopard DVD.

e4c5
After I posted my answer I noticed that you have said OS X 10.4 - I haven't tried running Netbeans 6.8 on it, not sure if there might be a compatibility issue with that. The last version of Netbeans I have used on Tiger is 6.5
e4c5
In my question, I included a terminal session in which javac compiled the file, but java produced errors. Perhaps I failed to make it clear because I insisted on using ; to perform all the commands at once.I have just started using NetBeans, and am almost positive that I haven't changed the default settings.
Dan
Are you talking about X11? I think I might've had that installed back when it was required to use OpenOffice on Mac. The xterm was able to compile and run my code without a problem. Does this mean I have to use it whenever I want to run code that involves dialog boxes via terminal?
Dan
Your attempt to run the program in the command line has been addressed in my answer that's where I speak of XWindow system, yes, it's X11If you are using this third party JVM , you will have to start up X11 before you attempt to run any java code that has a GUI
e4c5
Sorry for the late update, but upgrading to Snow Leopard seems to have eliminated this issue completely (presumably because I'm using its native, up-to-date JVM?).Thanks for your help e4c5!
Dan