IDEA中编译和运行java代码

IDEA中编译和运行java代码

本文介绍了无法在IntelliJ IDEA中编译和运行java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用InteliJ IDEA版本12.1.6我想从Horstmann的'Core Java'书中运行这个例子:

Using InteliJ IDEA version 12.1.6 I wanted to run the example from the Horstmann's 'Core Java' book:

public class Welcome
{
    public static void main(String[] args)
    {
        String[] greeting = new String[3];
        greeting[0] = "Welcome to Core Java";
        greeting[1] = "by Cay Horstmann";
        greeting[2] = "and Gary Cornell";

        for (String g : greeting)
        System.out.println(g);
    }
}

但是我收到以下错误:

"C:\Program Files\Java\jdk1.7.0_45\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\IntelliJ IDEA\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_45\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_45\jre\lib\ext\zipfs.jar;C:\Program Files (x86)\IntelliJ IDEA\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain Welcome
Exception in thread "main" java.lang.ClassNotFoundException: Welcome
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)

Process finished with exit code 1

在编译和执行文件的同时我在命令行中一切正常。对不起这个问题,我刚开始学习Java。 :)

At the same time when compiling and executing a file in the command line everything is working correctly. Excuse me for such a question, I just started learning Java. :)

推荐答案

谢尔盖,看起来你的想法是错误的。 上有一个分步教程,介绍了一些关于根的基本概念,运行配置,sdk-s和依赖项。
如果你看一下它会很好。 (探索项目结构特别构建(运行)项目

Sergey, it's look like you are working wrong with Idea. There is a step-by-step tutorial at wiki, that describes some basic concepts, about roots, run configurations, sdk-s and dependencies.It will be good, if you look at it. (Exploring the project structure and Building(Running) the project especially)

IDE是学习的好帮手语言,尤其是智能语言,因此,熟悉它是一个好的开始。

IDE is a great helper to learn language, especially such intellegent one, as Idea, so, it will be a good start, to get familiar with it.

基本上,首先,你的所有代码(未编译的类)必须在源根目录下,并且runConfiguration必须指定应用程序入口点(具有 static void main()方法的类)。

Basically, for a start, all your code(not compiled classes) must be under the source roots, and runConfiguration must specify application entry point (class with static void main() method).

您不应该考虑类文件,jar档案或命令行工具,IDEA可以为您完成所有这些。

You shouldn't think about class files, jar archives or command line tools, IDEA can do all this for you.

更好地专注于学习,正如我想的那样!

Better concentrate on learning, as I think!

这篇关于无法在IntelliJ IDEA中编译和运行java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:20