java - 如何解决这个似乎与对话框相关的运行时错误?

标签 java macos netbeans osx-tiger

(英特尔 Mac 操作系统 10.4.11、NetBeans IDE 6.8、SoyLatte 1.0.3)

虽然我目前正在学习 Java 大学类(class),并且我的代码是基于 Java 教科书中的几个问题,但我想非常清楚地表明,这不是家庭作业。这是为了学习目的而 self 分配的,我的教授可能永远不会看到它,更不用说评分了。不管怎样,我怀疑这是一个与配置相关的问题,因为我在校园的 Vista 机器上运行这个程序时没有遇到这样的问题。假设我是对的,这个社区的任何政策都不应该有任何问题,因为我不需要收到任何“应答”代码来解决这个问题。

在 NetBeans 中,我的程序可以编译并正常工作,但会产生一些运行时错误。知道这里会发生什么吗?

这是我的代码:

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


    }

}

以下是 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)

以下是一个故障排除终端 session ,使用 SoyLatte 提供的较新版本的 JDK( http://landonf.bikemonkey.org/static/soylatte/ ,它无法生成对话框)以及 Apple 提供的作为我的操作系统一部分的旧版本(例如在 NetBeans 中也可以正常工作,否则)。

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$ 

下面是一次错误的获取信息的尝试。来 self 的 Java 类实验室计算机上的 Windows Vista 环境,该计算机完美地编译并运行了该程序。是的,应该使用-version。如果需要解决此问题,我会更新它。

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>

我已经尽我所能在有限的时间内谷歌和搜索这个网站,但我自己却没有解决这个问题。除了在 super 用户和 AppleScript 方面有一点经验之外,我对 Stack Overflow 和编程都很陌生,所以请保持温柔。

最佳答案

第一个错误与您的代码无关。这可能是 Netbeans 配置错误或项目中的设置无效。如果您使用 javac 在命令行上编译代码并使用 java 运行它,那就没问题了。但这并不能回答你的问题。如果我是你,我会尝试重新安装 netbeans。

第二个错误表明您的 JVM 正在尝试在 XWindow 系统下运行您的代码。 XWindow 是Linux 的GUI 系统。幸运的是,有一个适用于 Mac 的版本,并且可以在您的雪豹 DVD 上找到。

关于java - 如何解决这个似乎与对话框相关的运行时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301207/

相关文章:

java - Cassandra - 无法启动,错误为 "Insufficient disk space to write 572 bytes"

java - 获取自某个日期以来的毫秒数

objective-c - 如何在 NSAnimationContext 结束时触发回调?

java - 将焦点设置到文本字段

java - 使用 NetBeans 连接到 Java 中的 Access 数据库

java - 使用 Context 对象从 fragment 内的 RecyclerView 访问 Activity 的 HashMap

java - 重命名所有风格的类

Java - Mac 应用程序需要安装 JDK 才能运行

ios - 如何使用 stat 实用程序而不是 subpathsOfDirectoryAtPath 来计算目录大小

templates - 如何在NetBeans中编辑getter和setter模板?