ScribtCode createt in Java

Hi I tried to convertsome of my scribt to java, but it seems not to work.

In my code I try to get all designelement in a Database by the method GetdocumentbyId.

It works well in scribt but does not in Java

Scribtcode that works:

Dim Doc As NotesDocument

Dim i As Long

For i=1 To 65535

Set Doc=Db.GetDocumentByID(Hex$(i))

Forall x In Doc.Items

Print x

End Forall

Next

When I activate my Java-code I get following message.

java.lang.NullPointerException

at JavaAgent.NotesMain(JavaAgent.java:16)

at lotus.domino.AgentBase.runNotes(Unknown Source)

at lotus.domino.NotesThread.run(NotesThread.java:208)

Javacode:

Session session = getSession();

AgentContext agentContext = session.getAgentContext();

Database db = agentContext.getCurrentDatabase();

long i;

for (i=1; i<=65535; i=i+1) {

String Hexstringvalue =Long.toHexString(i);

Document doc = db.getDocumentByID(Hexstringvalue);

Vector items = doc.getItems();

System.out.println(Hexstringvalue);

for (int j=0; j<items.size(); j++) {

Item item = (Item)items.elementAt(j);

System.out.println(“\t” + item.getName());

}

}

Subject: ScribtCode createt in Java

I think you can not guarantee that every ID is in your database. So when you make a getDocumentbyid with an id which is not there you get “null” back. So you must check in your code for null values.

Session session = getSession();

AgentContext agentContext = session.getAgentContext();

Database db = agentContext.getCurrentDatabase();

long i;

for (i=1; i<=65535; i=i+1) {

String Hexstringvalue =Long.toHexString(i);

Document doc = db.getDocumentByID(Hexstringvalue);

if (doc!=null){

Vector items = doc.getItems();

System.out.println(Hexstringvalue);

for (int j=0; j<items.size(); j++) {

Item item = (Item)items.elementAt(j);

System.out.println(“\t” + item.getName());

}

}

}

Greetings from Austria

Ralf M Petter

Subject: RE: ScribtCode createt in Java

I think I already check that the Doc not is Null.Other suggestions.

Subject: RE: ScribtCode createt in Java

In the code you have posted you do not check for null values!!! please post your actual code or i can not help you!

Subject: RE: ScribtCode createt in Java

Correct I did not test if the Doc was null.Thanks it works now.