-1

I get

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

from this code:

public class Book2 {
    String title;
    String author;

    void show() {System.out.println(title+" "+ author);

    public Book2() {
        this("", "");
        System.out.println("생성자 호출됨");
    }

    public Book2(String title) {
        this(title, "작자미상");
    }

    public Book2(String title, String author) {
        this.title = title;
        this.author = author;
    }

    public static void main(String[] args) {
        Book2 littlePrince = new Book2("어린왕자", "생텍쥐페리");
        Book2 loveStroy = new Book2("춘향전");
        Book2 emptyBook = new Book2();
        loveStroy.show();
        // bible.show();
    }
  }
}

I do not know which part is the error.

2
  • Welcome to Stack Overflow! Other users marked your question for low quality and need for improvement. I re-worded/formatted your input to make it easier to read/understand. Please review my changes to ensure they reflect your intentions. But I think your question is still not answerable. You should edit your question now, to add missing details (see minimal reproducible example ). Feel free to drop me a comment in case you have further questions or feedback for me. Commented Oct 15, 2018 at 4:31
  • First of all: this exception means: you try to run code that didn't compile properly. And then you get that exception. So point 1: dont try to run your code, compile it first, and make sure you fix all error messages. Commented Oct 15, 2018 at 4:32

2 Answers 2

1

There is also a syntax error here:

void show() {System.out.println(title+" "+ author);

You missed closing brace.

void show() {System.out.println(title+" "+ author);} 



(ins)-> javac Book2.java 
(ins)-> java Book2
생성자 호출됨
춘향전 작자미상
Sign up to request clarification or add additional context in comments.

Comments

0

Your code needs UTF-8 encoding checked, the error is because you are using default ASCII encoding.

Right click on your class file in eclipse --> go to properties --> Resource -->Text File endcoding at the bottom --> Select Other and choose UTF-8 from the dropdown.

If you are not using eclipse then while saving your java file save it with UTF-8 encoding.

The error will be gone. And you'll get the output as such -

생성자 호출됨 춘향전 작자미상

2 Comments

The UTF8 stuff looks correct, but the code still wont compile: there is a syntax error in the code.
@GhostCat Yes, you are right. He needs to first compile the code successfully.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.