The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by jroysdon]

Tony,

I wrote an agent that, when written in a procedural way, works fine. I am
trying to make it more of an OOP and am having trouble. Can you point me in
the right direction of what I am doing wrong?

mport java.util.Vector;
import lotus.domino.*;

public class PNewsletter
{

public PursuitNewsLetter x;

public PNewsletter(PursuitNewsLetter p)
{
this.x = p;
}

public void createNL()
{
try
{
Document nldoc = x.db.createDocument();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

import lotus.domino.*;
import java.util.*;

public class PursuitNewsLetter extends AgentBase {

public PNewsletter pnl;

public void NotesMain()
{
try
{
Session s = getSession();
AgentContext agentContext = s.getAgentContext();
Database db = agentContext.getCurrentDatabase();
pnl = new PNewsletter(this);
pnl.createNL();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


The error I am getting is:
No variable db defined in class PursuitNewsLetter

Thanks for your help and insight,

Jim
import-bot (20211) [Avatar] Offline
#2
Re: Forgive me for such a novice question
[Originally posted by jroysdon]

Gee, I answered my own question, and best of all, I understand it. It all had
to do with scope.

Inside a method, if you define a variable as:

Database db = session.getDatabase("whatever");

"db" has the scope of only that method.

I move the definition to public and outside that method and it worked fine.

Jim
import-bot (20211) [Avatar] Offline
#3
Re: Forgive me for such a novice question
[Originally posted by aspatton]

I'm glad I could help smilie

Tony.