-2

I have been watching these videos on youtube using the provided Source Code Examples from git hub link at the bottom, everything has been fine but I started getting these errors whenever I run the code

Error: Could not find or load main class mathexample.MathExample C:\Users\JAC\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

code:

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

  • Try to clean and rebuild the project –  Nov 06 '17 at 10:51
  • yeah tried that worked for a while when i wanted to add things to the code but now that doesn't work – Joshua Carpentier Nov 06 '17 at 10:55
  • If you use an IDE, check the "run configuration" for the project you try to run. I see this is from Netbeans ... [Check this](https://stackoverflow.com/questions/20034377/netbeans-error-could-not-find-or-load-main-class) – AxelH Nov 06 '17 at 10:59

1 Answers1

1

It looks like whichever IDE you're using, you haven't pointed it towards your main class. Try looking inside your project settings and see what it's trying to execute.

Sam
  • 1,234
  • 3
  • 17
  • 32