1

I tried to run the code from Head First Java as the following:

public class PhraseOMatic {
   public static void main(String[] args){

    String[] wordListOne = {"24/7", "mult-iTier", "30,000 foot", "B-to-B", "win-win", "front-end", "web-based", "pervasive", "smart", "six-sigma", "critical-path", "dynamic"};

    String[] wordListTwo = {"empowered", "sticky", "value-added", "oriented", "centric", "distributed", "clustered", "branded", "outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"};

    String[] wordListThree = {"process", "tipping-point", "solution", "architecture", "cor competency", "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"};

    int oneLength = wordListOne.length;
    int twoLength = wordListTwo.length;
    int threeLength = wordListThree.length;

    int rand1 = (int) (Math.random() * oneLength);
    int rand2 = (int) (Math.random() * twoLength);
    int rand3 = (int) (Math.random() * twoLength);

    String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];

    System.out.println("What we need is a " + phrase);
    }
}

and it is here that I receive this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at PhraseOMatic.main(apples.java:2)

I see from the error that the problem is in line 2, but I can identify the error

4
  • i compile and run the program no error occur Commented Aug 27, 2012 at 4:51
  • Please post the code along with package statement so we can help you out. Commented Aug 27, 2012 at 4:53
  • 1
    @AVD That appears to be all of OP's code. Regardless, OP provided sufficient information to solve the issue: class PhraseOMatic is saved in a file named "apples.java". Commented Aug 27, 2012 at 4:58
  • I think there is an IDE and may be OP has removed package statement or something else. Commented Aug 27, 2012 at 5:02

3 Answers 3

2

Have a look at exception trace (PhraseOMatic.main(apples.java:2)). Your public class PhraseOMatic must be saved with PhraseOMatic.java file. Name of top-level public class and .java file must be same.

Sign up to request clarification or add additional context in comments.

1 Comment

Rename your .java file to PhraseOMatic.java. Do you have IDE (netbeans/eclipse etc)?
0

Just look at PhraseOMatic.main(apples.java:2). Your file is named apples.java, but in Java your files HAVE to have the same name as your classes. In your case PhraseOMatic.java.

Comments

0

your stake trace:

PhraseOMatic.main(apples.java:2)

So you are missing to run java to level class; your java main class is PhraseOMatic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.