GUI Application for writing Notes

Hello fellow programmers. I am writing a GUI application in JAVA that can write notes and read them, add them to a text file and etc.

My problem: GUI Application reads and finds the note.txt file but does not add the writen text to it.

Here is one of the classes from my project that is responsible for adding and reading notes (I think the error comes somewhere from there, shame that I can’t add the whole project here):

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
*
* @author justcain
*/
public class AllNotes extends CommonCode {

ArrayList<Note> allNotes = new ArrayList<>();
private String crse = “”;
private int maxID = 0;

AllNotes() {
readAllNotes();
}

public final int getMaxID() {
maxID++;
return maxID;
}

private void readAllNotes() {
ArrayList<String> readNotes = new ArrayList<>();

readNotes = readTextFile(appDir + fileSeparator + “\Notes.txt”);
//System.out.println(readNotes.get(0));

if (!“File not found”.equals(readNotes.get(0))) {
allNotes.clear();
for (String str : readNotes) {
String tmp = str.split("\t");
System.out.println(str);

Note n = new Note();
n.setNoteID(Integer.parseInt(tmp[0]));
n.setCourse(tmp[1]);
n.setDayte(tmp[2]);
n.setNote(tmp[3]);

allNotes.add(n);

/*int nid = Integer.parseInt(tmp[0]);
Note n = new Note(nid, tmp[1], tmp[2], tmp[3]);
allNotes.add(n);

if (nid > maxID) {
maxID = nid;
}*/

}
}
maxID++;
}

public void addNote(int maxID, String course, String note) {
Note myNote = new Note(maxID, course, note);
allNotes.add(myNote);
writeAllNotes();
}

public ArrayList<Note> getAllNotes() {
return allNotes;
}

private void writeAllNotes() {
String path = appDir + fileSeparator + “\Notes.txt”;
ArrayList<String> writeNote = new ArrayList<>();

for (Note n : allNotes) {
String tmp = n.getNoteID() + “\t”;
tmp += n.getCourse() + “\t”;
tmp += n.getDayte() + “\t”;
tmp += n.getNote();
writeNote.add(tmp);
}
try {
//FileWriter writer = new FileWriter(“path”);
//BufferedWriter bw = new BufferedWriter(writer);
writeTextFile(path, writeNote);
} catch (IOException e) {
System.out.println("Problem! " + path);
}
}

public String searchAllNotesByKeyword(String noteList, int i, String s) {
if (i == allNotes.size()) {
return noteList;
}

if (allNotes.get(i).getNote().contains(s)) {
noteList += allNotes.get(i).getNote() + “\n”;
}

return searchAllNotesByKeyword(noteList, i + 1, s);
}

}

Hi @justcain,

Welcome to the Github Community Forum!   

Do you have a github repository? So we can analyze better your code!

-Gabriele-  

Mark helpfull posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great contents!

Just created it. Pretty new to github ;d

Feel free to give advice in any other parts of the code.

Is this the repository? https://github.com/justcain/GUI-Easy-snippets

-Gabriele-

Mark helpfull posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great contents!

Yes it is. The classes are in the SRC folder.

Missing File.CreateNew() in WriteAllText.