Post

2 followers Follow
0
Avatar

Class DocumentNoteUtilities example code

In the documentation for this class you have some example code  of the form ...

java.util.List noteFields = new ArrayList();
String fieldCode = "Country";
noteFields.add(DocumentNoteField.createTextNoteField("Country", "country where specimen collected", fieldCode, Collections.emptyList(), false));
String noteTypeCode = "DocumentNoteUtilities-TestNote";
DocumentNoteType noteType = DocumentNoteUtilities.getNoteType(noteTypeCode);
if (noteType == null) { //create and add the note type if it hasn't already been added
noteType = DocumentNoteUtilities.createNewNoteType("Test Note", noteTypeCode, "A test note", noteFields, true);
DocumentNoteUtilities.setNoteType(noteType);
}
DocumentNote note = noteType.createDocumentNote();
note.setFieldValue(fieldCode, "A value!");
AnnotatedPluginDocument.DocumentNotes documentNotes = doc.getDocumentNotes(true);
documentNotes.setNote(note);
documentNotes.saveNotes();

Using the Geneious Plugin  SDK under Eclipse 32 bit I get the error ...

The method createTextNoteField(String, String, String, List<Constraint>, boolean) in the type DocumentNoteField is not applicable for the arguments (String, String, String, List<Object>, boolean)

Any ideas? It's probably something trivial - I'm not a Java developer

Jerry Cooper

Please sign in to leave a comment.

5 comments

0
Avatar

Hi there.  It sounds like this documentation is incorrect, but I'm having trouble tracking it down. Whereabouts is this documentation?  Is this the latest version (6.0.5) of the plugin development kit?

Amy Wilson 0 votes
Comment actions Permalink
0
Avatar

I get the same result with plugin SDK 6.05 or 6.03.

The example code is at ...

/geneious-devkit/geneious-6.0.5-devkit/api-javadoc/com/biomatters/geneious/publicapi/documents/DocumentNoteUtilities.html

Jerry Cooper 0 votes
Comment actions Permalink
0
Avatar

There's code that looks similar to what you've got up there in DocumentNoteUtilities.html, but the first 3 lines are different.  They read:

java.util.List noteFields = new ArrayList();
    String fieldCode = "Field1";
    noteFields.add(DocumentNoteField.createTextNoteField("Field no.1", "The first field", fieldCode, Collections.emptyList(), false));

Are the first 3 lines an adaptation of the code you have made yourself?  If so, you can make it compile by adding the <Constraint> back in on line 2.

Amy Wilson 0 votes
Comment actions Permalink
0
Avatar

OK. It works if I make the cast ...

    String fieldCode = "Field1";
    noteFields.add(DocumentNoteField.createTextNoteField("Field no.1", "The first field", fieldCode, (List) Collections.emptyList(), false));

        

Jerry Cooper 0 votes
Comment actions Permalink
0
Avatar

The method takes a list of constraints.  When it just said Collections.emptyList(), it was creating a list of Objects.  With Collections.<Constraint>emptyList() as in the example, it creates a list of Constraints.  With (List)Collections.emptyList(), it creates a list of unknown type.

Although using (List)Collections.emptyList() won't cause problems in this case, I suggest you get into the habit of using the form Collections.<Constraint>emptyList() because in other similar situations this will avoid bugs.

Amy Wilson 0 votes
Comment actions Permalink