Question: My Eclipse keeps showing this message when I try to run it and I don't know what to do. (Code and error below) A named

My Eclipse keeps showing this message when I try to run it and I don't know what to do. (Code and error below)

A named package because this compilation unit is associated to the named module 'Database2'

Database2 is the name of my project

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String data = "";

while (true) {

System.out.println("Please choose one of the following: 1. show names 2. add name 3. exit");

int choice;

choice = sc.nextInt();

if (choice == 1) {

try {

File myObj = new File("file.txt");

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

data = myReader.nextLine();

System.out.println(data);

}

myReader.close();

} catch (FileNotFoundException e) {

System.out.println("An error occurred.");

System.out.println("Add something to the file first");

}

} else if (choice == 2) {

System.out.println("Enter name to add");

String name = sc.next();

data += (" " + name + " ");

try {

FileWriter myWriter = new FileWriter("file.txt");

myWriter.write(data);

myWriter.close();

System.out.println("Successfully wrote to the file.");

} catch (IOException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

}

else break;

}

sc.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!