Run-time error

hi all,I’m doing a program that making a remote call to read the Domino Address Book information, but it gives me a run-time error.

Here is my code

import main.*;

import network.*;

import utils.*;

import lotus.domino.*;

import java.io.PrintWriter;

public class ReadAddress extends AgentBase //NotesThread

{

//NotesMain method is the entry point for Domino Java Agent

public void NotesMain()

{

	try

	{

		//Create a Session object

		Session s = NotesFactory.createSession(); 

 		//Session s = this.getSession();

 		// PrintWriter object use to printoutput

 		PrintWriter pw = this.getAgentOutput();

 		//Create a Database object; we will use the name and address book

		Database db = s.getDatabase("servername","names.nsf");

		//Continue only if the database was properly instantiated

		if (db != null)

		{

			//create a View object using the list of people in the NAB

			View vw = db.getView("People");

			//Continue only if the View object has been properly instantiated

			if (vw != null)

			{

				//Retrieve the first document in the view

				Document doc = vw.getFirstDocument();

				//Declare String objects to be used for field values

				String fname = null;

				String lname = null;

				int c = 0;

				//Loop through all documents in the view;

				while (doc != null)

				{

					c += 1;

					//Retrieve the contents of the FirstName and lastname field as a String

					fname = doc.getItemValueString("FirstName");

					lname = doc.getItemValueString("LastName");

					//display name and counter variable

					pw.println("Person #" + c + " : " + fname + " " + lname);

					//added here

					Document prevdoc = doc;

					//Get next document from the view

					doc = vw.getNextDocument(doc);

					//added here

					 prevdoc.recycle();



				}

				//return memory used by View object to the system

				vw.recycle();

			}

			//Return memory used by Database object to the system

			db.recycle();

		}

		//Return memory used by Session object to the system

		s.recycle();

	} 

	catch(Exception e) 

	{

		e.printStackTrace();

	}

}

}

//call function here

import network.*;

import utils.*;

import main.*;

import lotus.domino.*;

import java.io.PrintWriter;

import org.omg.CORBA.ORB;

class callReadAddress{

public static Config config;

public static void main(String args[]){

	Config config = new Config();

	DiiopAccess diiop = new DiiopAccess();

        diiop.setServer(config.getDiiopHost());

        diiop.setPort(config.getDiiopPort());

      

ReadAddress ra = new ReadAddress();

ra.NotesMain();

}

}

Can someone tell what is wrong with my code and what else i need to set?

Subject: Probably here…

Document prevdoc = doc;//Get next document from the view

doc = vw.getNextDocument(doc);

//added here

prevdoc.recycle();

Try this:

//Delete this line! Document prevdoc = doc;

//Get next document from the view

doc = vw.getNextDocument(doc);

//added here

//Delete this line! prevdoc.recycle();

Here’s the logic:

you always solve what’s in the parenthesis first. This means that getNextDocument(doc) is the old instantiation, leading to the "doc = " definition.

Don’t make things more complicated than they have to be! By instantiating prevdoc, then recycling it, you just waste time.

Hope this helps.

Marcus

Subject: RE: Probably here…

i do what u said before, but it still gives me the same error, i think i have miss something that need to be set, I’m making a remote called with DIIOP task running at the back, i gope that u may help on this, thank you very much.

Subject: RE: Probably here…

Does it work without DIIOP?

Check that first. You can make a local copy of names.nsf from the server and try to loop through all of the names.

By the way, it’s a good practice to put some debugging code into your java. Here’s a quick way to do it:

boolean trace = true;

if (trace) System.out.println( "Put your debug comments and code here, computing, then printing variables to the console… )

Check the Java console for your output, and you can tell the exact line where you are bombing out.

When you’re done, you can just set trace to false. That will turn all of the output to the console off. There are other more complex ways of debugging, but I’ve found this to be the easiest.

Marcus

P.S. After debugging like I showed you, let me know what line you are having problems with. We can probably find out quickly what the real problem is.

Subject: RE: Probably here…

I should copy the names.nsf into which directory?

Subject: RE: Probably here…

really down’t matter. just make sure that you don’t overwrite your personal names.nsf.

If you pull a replica, call it something like OrgNames.nsf where Org is the name of your organization. This way, when you look at them in your File - Database - Open dialog, you will be able to see the difference quickly!

It will also help you look for names in the Server Directory when you are offline.

Subject: RE: Probably here…

Thks for ur reply again, i don’t have any Lotus Notes install locally, beside this, what else i need to change on my coding in order to test the “local call” senario?

Subject: Set server name to “”

Change this line:

Database db = s.getDatabase(“servername”,“names.nsf”);

to

Database db = s.getDatabase(“”,“OrgNames.nsf”);

Terrance, I’m afraid you’re going at this whole thing backwards. I’m not an IIOP specialist. I do know that I’ve never run a line like the following:

ra.NotesMain();

Can anyone else help?

Marcus

Subject: RE: Set server name to “”

nvm, we go step-by-step, make sure that i can read the address book locally first.

Subject: RE: Set server name to “”

it gives me the following errors

xception in thread “main” java.lang.UnsatisfiedLinkError: NCreateSession

    at lotus.domino.local.Session.NCreateSession(Native Method)

    at lotus.domino.local.Session.createSession(Session.java:94)

    at lotus.domino.NotesFactory.createSession(Unknown Source)

    at ReadAddress.NotesMain(ReadAddress.java:16)

    at callReadAddress.main(callReadAddress.java:39)

Subject: RE: Probably here…

I try to disable all the codes in my callReadAddress and only has these 2 lines of codesReadAddress ra = new ReadAddress();

			ra.NotesMain();

and it gives me the following errors

at lotus.domino.local.Session.NCreateSession(Native Method)

    at lotus.domino.local.Session.createSession(Session.java:94)

    at lotus.domino.NotesFactory.createSession(Unknown Source)

    at ReadAddress.NotesMain(ReadAddress.java:16)

    at callReadAddress.main(callReadAddress.java:39)

Subject: Here, start with this… run this in an agent…

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

	boolean trace = true;

	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();

		Database db = session.getDatabase("","OrgNames.nsf");

		if (trace) System.out.println( "Got db" ) ;

		View view = db.getView("($VIMPeople)");

		if (trace) System.out.println( "Got view" ) ;

		Document doc = view.getFirstDocument();

		if (trace) System.out.println( "Got first Doc" ) ;

			while (doc != null) {

     			System.out.println("\t" + doc.getItemValueString("LastName") + ", " + 

				doc.getItemValueString("LastName") + "\n" );

    			doc = view.getNextDocument(doc); 

		}

		if (trace) System.out.println( "Finished!" ) ;



	} catch(Exception e) {

		e.printStackTrace();

	}

}

}

Subject: RE: Here, start with this… run this in an agent…

hi.i make use of the notes.jar files, is it not suitable for Linux?

Subject: RE: Here, start with this… run this in an agent…

Thks for ur help again

this is the error that i get while running your code

java.lang.NullPointerException

    at ReadAddress.NotesMain(ReadAddress.java:16)

    at callReadAddress.main(callReadAddress.java:39)

Subject: Took this code into Netbeans…Otherwise, I don’t know how to help

import lotus.domino.*;

public class Terrance extends AgentBase {

public void NotesMain() {

	boolean trace = true;

	try {

                    Session session = NotesFactory.createSession( "server","user", "password");

		Database db = session.getDatabase("","OrgNames.nsf");

		if (trace) System.out.println( "Got db" ) ;

		View view = db.getView("($VIMPeople)");

		if (trace) System.out.println( "Got view" ) ;

		Document doc = view.getFirstDocument();

		if (trace) System.out.println( "Got first Doc" ) ;

			while (doc != null) {

     			System.out.println("\t" + doc.getItemValueString("LastName") + ", " + 

				doc.getItemValueString("LastName") + "\n" );

    			doc = view.getNextDocument(doc); 

		}

		if (trace) System.out.println( "Finished!" ) ;



	} catch(Exception e) {

		e.printStackTrace();

	}

}



    public static void main( String [] args )

    {

          Terrance t = new Terrance();

        t.NotesMain();

    }

}

Hope someone else has experience because DIIOP isn’t installed on my server.

Marcus

Subject: RE: Took this code into Netbeans…Otherwise, I don’t know how to help

is it because that the notes.jar that i use is not suitable to use on Linux?

Subject: Run-time error

It would really help to post the stacktrace of the run-time error. Without the details we’d be guessing where the problem might be…