1

I am working on a JSF based Web Application where I read contents from a file(dumpfile) and then parse it using a logic and keep adding it to a list using an object and also set a string using the object. But I keep getting this error. I am confused where I am wrong. I am a beginner so can anyone be kind enough to help me?

List<DumpController> FinalDumpNotes;
public List<DumpController> initializeDumpNotes()
throws SocketException, IOException {
PostProcessedDump postProcessedDump = (PostProcessedDump) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("postProcessedDump");
List<DumpController> FinalNotes = new ArrayList<>();
if (postProcessedDump.getDumpNotes() == null) {
dumpNotes = new DumpNotes();
}
DumpListController dlcon = (DumpListController) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("dumpListController");
DumpInfo dumpinfo = dlcon.getSelectedDumpInfo();
String fileName = dumpinfo.getDate() + dumpinfo.getTime() + dumpinfo.getSeqNo() + dumpinfo.getType() + dumpinfo.getTape() + dumpinfo.getDescription() + ".txt";
if (checkFileExistsInWin(fileName)) {
postProcessedDump.setDumpnotescontent(getFileContentsFromWin(fileName));
String consolidateDumpnotes = getFileContentsFromWin(fileName);
String lines[];
String content = "";
lines = consolidateDumpnotes.split("\\r?\\n");
List<String> finallines = new ArrayList<>();
int k = 0;
for (int i = 0; i < lines.length; i++) {
if (!lines[i].equalsIgnoreCase("")) {
finallines.add(lines[i]);
k++;
}
}
for (int j = 0; j < finallines.size(); j++) {
if (finallines.get(j).startsWith("---------------------SAVED BY")) {
PostProcessedDump dump = new PostProcessedDump();
dump.setDumpMessage(content);
content = "";
FinalDumpNotes.add(dump);
} else {
content = content + finallines.get(j);
}
}
}
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("postProcessedDump", postProcessedDump);
return FinalDumpNotes;
}

I get the following error: enter image description here

2
  • 1
    because they are not from same type!your FinalDumpNotes is a collection of DumpController and your dump is PostProcessedDump. Commented Jun 7, 2015 at 15:15
  • 1
    Did you actually take a picture of your monitor to provide that screenshot? That kinda cheers me up :) Commented Jun 7, 2015 at 16:55

2 Answers 2

1

If you want to add instances of type PostProcessedDump to your List you should change it's type. Also, don't forget to initialize it. Something like,

List<PostProcessedDump> FinalDumpNotes = new ArrayList<>();

Also, Java naming convention is to start variable names with a lower case letter. FinalDumpNotes looks like a class, I would suggest something like

 List<PostProcessedDump> processedList = new ArrayList<>();
Sign up to request clarification or add additional context in comments.

Comments

1

Problems with your code:

List<DumpController> FinalDumpNotes;

You declare FinalDumpNotes to be a List of DumpController objects, but you never initialize it. In addition, your IDE is barfing on the following line of code:

FinalDumpNotes.add(dump);

because you are attempting to add a PostProcessedDump object to the List instead of a DumpController object.

For starters, you need to initialize your list like this:

List<DumpController> finalDumpNotes = new ArrayList<DumpController>();

Notice that I have made the variable name beginning with lower case, which is the convention (upper case is normally reserved for classes and interfaces).

I will leave it to you as a homework assignment to sort out the correct usage of this List.

2 Comments

I replaced my line with yours and still same error persists
Your code is in a mess. The answers given here explain the error you were seeing in your IDE.

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.