【问题标题】:hi so i have a error keeping my code from running? [closed]嗨所以我有一个错误阻止我的代码运行? [关闭]
【发布时间】:2017-11-06 10:48:55
【问题描述】:

我一直在使用底部 git hub 链接中提供的源代码示例在 youtube 上观看这些视频,一切都很好,但是每当我运行代码时我开始收到这些错误

错误:无法找到或加载主类 mathexample.MathExample C:\Users\JAC\AppData\Local\NetBeans\Cache\8.2\executor-sn-ps\run.xml:53:Java 返回:1 构建失败(总时间:0 秒)

代码:

package mathexample;

import java.util.Random;
import java.util.Scanner;

public class MathExample {

    public static void main(String[] args) {
        System.out.println("//Math Example //////////////////////////////////");
        // Circle Math
        Scanner input = new Scanner(System.in);
        System.out.print("Enter Circle Radius : ");
        double radius = input.nextDouble();
        double circ = 2*Math.PI*radius;// using math library
        double area = Math.PI*radius*radius;
        System.out.printf("Circumfrence : %f; Area : %f\n",circ, area);   
        System.out.println("///////////////////////////////////////////////\n");

        System.out.println("//RandomExample /////////////////////////////////");
        // Demonstrates use of an existing class
        //random class
        Random generator = new Random();    // 0 is the "seed" the same seed will
                                            // generate the same random sequence
                                            // Random() will use a random "seed"        
        int i = generator.nextInt(10);      // pick a random number between 0 and 9
        System.out.println(i);
        i = generator.nextInt(10);// java doc explains classes right click to access it
        System.out.println(i);
        i = generator.nextInt(10);
        System.out.println(i); 
        System.out.println("///////////////////////////////////////////////\n");

        System.out.println("//StringBuilderExample //////////////////////////");
        // demonstrates StringBuilder class
        StringBuilder sb = new StringBuilder();//uses javadoc the learn
        sb.append("This is a test!");
        String forward = sb.toString();//you only need (new) when creating a new object 
        String reverse = sb.reverse().toString();// this uses the existing object 
        // on line 7 StringBuilder

        System.out.println(forward);
        System.out.println(reverse);
        System.out.println("/////////////////////////////////////////////////");

    }
}

https://github.com/mafudge/LearnJava

【问题讨论】:

  • 尝试清理并重建项目
  • 是的,当我想向代码中添加内容时,它尝试了一段时间,但现在不起作用
  • 如果您使用 IDE,请检查您尝试运行的项目的“运行配置”。我看到这是来自 Netbeans ...Check this

标签: java


【解决方案1】:

看起来无论您使用的是哪个 IDE,您都没有将它指向您的主类。尝试查看您的项目设置,看看它试图执行什么。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-01
  • 1970-01-01
  • 2021-11-18
  • 2020-04-01
相关资源
最近更新 更多