Action Listener - create view when button is pressed

Hi everybody!

I’m quite new to Domino and Java and I have a problem.

I create a form (where the user can enter some text - that’s not in the source code below)

and then presses a button. When pressing the button a view should be created. This

happens in a seperated method. The problem is that the view cannot be created, because

the database is null.

What can I do to create a view when the button is pressed?

I would be very grateful if anybody could help me.

Thanks.

This is my code:

import lotus.domino.*;

import javax.swing.*;

import java.awt.*;

import java.lang.*;

import java.util.Vector;

import java.awt.event.*;

public class JavaAgent extends AgentBase {

  private Session session;

  private AgentContext agentContext;	

  private Database db;

  private Document doc;



public void NotesMain() {



	try {

		

		session = getSession();

		agentContext = session.getAgentContext();	   	

		db = agentContext.getCurrentDatabase();

	

		 Fenster screen = new Fenster(db, session,"BPC Requirements and LIs");

		 screen.pack();

		 screen.setVisible(true);



	}catch(Exception e) {

		 JOptionPane.showMessageDialog(null, "NotesMain-Exeption: "+e.getMessage());

 	      e.printStackTrace();

	}

}

}


import lotus.domino.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class Fenster extends JFrame implements ActionListener{

private JPanel flaeche;

private JButton senden;

private Database db2;

private View myView;

private Session session;

public Fenster(Database db, Session session, String titel)

{

super(titel);



try{

	

this.db2=db;

this.session=session;



flaeche = new JPanel();   



flaeche.setLayout(new GridLayout(0,2));

flaeche.setBorder(BorderFactory.createEmptyBorder());



senden = new JButton("Submit");

flaeche.add(senden);



 this.getContentPane().add(flaeche);    



senden.addActionListener(this) ;



}

	catch(Exception e) {

		 JOptionPane.showMessageDialog(null, "NotesMain-Exeption: "+e.getMessage());

 	      e.printStackTrace();

	}

} // end Konstruktor

public void actionPerformed(ActionEvent e)

{

	if(e.getSource() == senden)	{	sendenPressed();	}

}

public void sendenPressed(){

myView=db.createView("MyView", "SELECT @All");	// view cannot be created	

}

}