简体   繁体   English

在Windows 7上第一次设置JAVA时出现问题

[英]Problem While Setting up JAVA fro the 1st time on Windows 7

I installed the J2SE 6.o version. 我安装了J2SE 6.o版本。 Now I'm having a problem getting it to work right. 现在,我无法正常工作。

> C:\java\jdk1.6.0_25\bin

This is the path of the bin file, and I put this in the Path tab. 这是bin文件的路径,我将其放在“路径”选项卡中。 In the environment settings. 在环境设置中。

What are the next steps that I have to take to run .java files from the command prompt? 从命令提示符运行.java文件时,我需要采取哪些下一步措施?

Do I have to put something in the class-path tab too? 我也必须在“类路径”选项卡中添加一些内容吗?

Let me elaborate my problem: 让我详细说明我的问题:

If I run and compile the below mentioned file called Shirt.java it works fine. 如果我运行并编译下面提到的名为Shirt.java文件,它将正常工作。

public class Shirt{
public int ShirtID=0;
public String description="-description required-";
public char colorCode='U';
public double price=0.0;
public int quantityInStock=0;


public void displayShirtInformation(){
    System.out.println("ShirtId:"+ShirtID);
        System.out.println("ShirtDescription"+description);
        System.out.println("Color Code:"+colorCode);
        System.out.println("Shirt Price"+price);
        System.out.println("Quantity In Stock"+quantityInStock);
    }
}

But if I run another file that calls the previous file, then problems crop up. 但是,如果我运行另一个调用前一个文件的文件,则会出现问题。 The file that calls the previous file is as follows. 调用前一个文件的文件如下。

public class ShirtTest {

  public static void main (String args[]) {

  Shirt myShirt = new Shirt();

  myShirt.displayShirtInformation();

  } 
}

When I try to execute the second file, there are a few errors that crop up and no compilation takes place. 当我尝试执行第二个文件时,会出现一些错误,并且不会进行编译。 I believe it has something to do with some problem with the environment variable Path declaration. 我相信这与环境变量Path声明的某些问题有关。

I would use an IDE, this avoid the need to 我会使用一个IDE,这样可以避免

  • setup the path 设置路径
  • check that all the classes you need have been compiled. 检查是否已编译了所需的所有类。
  • setup the classpath for the java 设置java的类路径

Instead all you need to do is hit the Run button and it does the rest. 相反,您需要做的就是点击“ Run按钮,其余的工作就完成了。

It may even help you write/format the code and generate a toString() method, getters/setters and unit tests for it. 它甚至可以帮助您编写/格式化代码并为其生成toString()方法,获取器/设置器和单元测试。

路径设置不会有任何问题,因为第一个Java文件正在工作,否则它将给出“无法将'java'识别为内部或外部命令”错误。

It is better to make sure that you do not have a CLASSPATH environment variable set. 最好确保没有设置CLASSPATH环境变量。 If it is not set, Java will by default look in the current directory for class files. 如果未设置,默认情况下Java将在当前目录中查找类文件。 As long as your Java source files are in the same directory (and not in a package) you should be able to compile and run them with simple commands: 只要您的Java源文件位于同一目录(而不是程序包中),您就可以使用简单的命令来编译和运行它们:

javac Shirt.java
javac ShirtTest.java
java ShirtTest

If this complains with a NoClassDefFoundError , then try specifying the classpath on the command line using the -cp option: 如果此命令带有NoClassDefFoundError ,则尝试使用-cp选项在命令行上指定类路径:

javac -cp . Shirt.java
javac -cp . ShirtTest.java
java -cp . ShirtTest

(note that . means "the current directory"). (请注意, .表示“当前目录”)。

See the Getting Started tutorial , which also has a section on common problems and their solutions. 请参阅入门教程 ,该教程也包含有关常见问题及其解决方案的部分。

When you get an error, please always copy & paste the exact error message, instead of just saying "I get some errors". 遇到错误时,请始终复制并粘贴确切的错误消息,而不仅仅是说“我遇到了一些错误”。 The more specific information you give, the easier it is to understand what the exact problem it is and the better we can help you. 您提供的信息越详细,越容易了解确切的问题,并且我们可以为您提供更好的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 第一次设置JPanel / JFrame背景图片 - Setting JPanel/JFrame background image, my 1st time java 交换最后一个和第一个字符串 - 问题适用于 3 但不适用于 4 - java swap last and 1st strings - problem works for 3 but not for 4 如何通过单击第一个Java Windows应用程序(Jframe)中的菜单项启动第二个Jframe - How to start 2nd Jframe by click menu item in 1st java windows application (Jframe) KeyListener第一次没有响应吗? - KeyListener is unresponsive 1st time used? 当软件在该系统中第一次运行时,如何使用Java显示对话框 - How to show a dialog box a software using java when the software run 1st time in that system 带有Scribe的Java Twitter客户端(第一次使用它)。 如何发布状态? - Java Twitter Client with Scribe (1st time using it). How to post status? Java编译器在出现第一个“ unreachable statement”错误时停止,同时还有许多其他错误。 为什么? - Java compiler stops on 1st “unreachable statement” error while many other errors remaining. Why? Tensorflow Java API-第1次预测时间与第2次或更长时间 - Tensorflow java api - 1st prediction time vs 2nd, or more 在Macos 10.13.2上设置IntelliJ时出现问题 - Problem while setting up IntelliJ on Macos 10.13.2 TreeMap java 实现 - 放置第一个元素 - TreeMap java implementation - putting 1st element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM