java.lang.NullPointer

i'm doing birt report integrating with eclipse rcp.

in the action file below:

protected Action printAction = new Action(){

{ setText("Print");

setId("print");

}

public void run() {

String frmSql = "FROM SP_PO inner join SP_PO_ITEM on SP_PO.ID=SP_PO_ITEM.PO_ID ";

String whrSql = "WHERE SP_PO.ID='07' ";

String sql = frmSql+whrSql;

String uri = Global.BIRT_REPORT_PATH+"Sp_Req_print.rptdesign&stmt= "+sql+"";

WebBrowser wb = new WebBrowser();

try {

wb = (WebBrowser)site.getPage().showView(WebBrowser.ID_VIEW);

wb.setUrl(uri);

} catch (PartInitException e) {

e.printStackTrace();

}

}

};

i got this error:

Unhandled event loop exception

Reason:

java.lang.NullPointerException

can anyone tell me how to solve the null pointer error?

[890 byte] By [moonnya] at [2007-11-26 12:41:39]
# 1

Hey, if you would also provide the URI, I'm sure I can grab all your DB's content using SQL injection. Use PreparedStatements.

Also, learn to use code tags.

http://forum.java.sun.com/help.jspa?sec=formatting

Third, learn to search, there is only one sort of problems that causes an NPE to occur.

Fourth, provide a useful error message. So somewhere an NPE happens, but you don't tell us where.

CeciNEstPasUnProgrammeura at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks..anyway my nullPointer error is at line wb = (WebBrowser)site.getPage().showView(WebBrowser.ID_VIEW);
moonnya at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 3
So either site or site.getPage is null. Unless showView is defined to throw a NPE for some reason.
CeciNEstPasUnProgrammeura at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 4

thanks,CeciNEstPasUnProgrammeur

then how to unset the null value of them?

the WebBrowser.java is as shown below:

public class WebBrowser extends ViewPart {

public static final String ID_VIEW = "report.WebBrowser";

private Browser browser;

private Text location;

private HTMLPage page;

private Action backAction = new Action() {

{ setText("Back"); }

public void run() {

browser.back();

}

};

private Action forwardAction = new Action() {

{ setText("Forward"); }

public void run() {

browser.forward();

}

};

private Action stopAction = new Action() {

{ setText("Stop"); }

public void run() {

browser.stop();

}

};

private Action refreshAction = new Action() {

{ setText("Refresh"); }

public void run() {

browser.refresh();

}

};

private Action goAction = new Action() {

{ setText("Go"); }

public void run() {

browser.setUrl(location.getText());

}

};

public WebBrowser() {

}

public void createPartControl(Composite parent) {

page = new HTMLPage(parent, SWT.NONE);

//browser = createBrowser(parent, getViewSite().getActionBars());

//browser.setUrl("http://127.0.0.1:8181/birt/"); //$NON-NLS-1$

}

public void setFocus() {

page.setFocus();

/*if (browser != null && !browser.isDisposed())

browser.setFocus();*/

}

public void setUrl(String url){

page.setUri(url);

}

public Browser createBrowser(Composite parent, final IActionBars actionBars) {

GridLayout gridLayout = new GridLayout();

gridLayout.numColumns = 3;

parent.setLayout(gridLayout);

Label labelAddress = new Label(parent, SWT.NONE);

labelAddress.setText("A&ddress");

location = new Text(parent, SWT.BORDER);

GridData data = new GridData();

data = new GridData();

data.horizontalAlignment = GridData.FILL;

data.horizontalSpan = 2;

data.grabExcessHorizontalSpace = true;

location.setLayoutData(data);

browser = new Browser(parent, SWT.NONE);

data = new GridData();

data.horizontalAlignment = GridData.FILL;

data.verticalAlignment = GridData.FILL;

data.horizontalSpan = 3;

data.grabExcessHorizontalSpace = true;

data.grabExcessVerticalSpace = true;

browser.setLayoutData(data);

browser.addProgressListener(new ProgressListener() {

IProgressMonitor monitor = actionBars.getStatusLineManager().getProgressMonitor();

boolean working = false;

int workedSoFar;

public void changed(ProgressEvent event) {

//System.out.println("changed: " + event.current + "/" + event.total);

if (event.total == 0) return;

if (!working) {

if (event.current == event.total) return;

monitor.beginTask("", event.total); //$NON-NLS-1$

workedSoFar = 0;

working = true;

}

monitor.worked(event.current - workedSoFar);

workedSoFar = event.current;

}

public void completed(ProgressEvent event) {

//System.out.println("completed: " + event.current + "/" + event.total);

monitor.done();

working = false;

}

});

browser.addStatusTextListener(new StatusTextListener() {

IStatusLineManager status = actionBars.getStatusLineManager();

public void changed(StatusTextEvent event) {

//System.out.println("status: " + event.text);

status.setMessage(event.text);

}

});

browser.addLocationListener(new LocationListener() {

public void changed(LocationEvent event) {

location.setText(event.location);

}

public void changing(LocationEvent event) {

}

});

location.addListener(SWT.DefaultSelection, new Listener() {

public void handleEvent(Event e) {

browser.setUrl(location.getText());

}

});

actionBars.setGlobalActionHandler("back", backAction); //$NON-NLS-1$

actionBars.setGlobalActionHandler("forward", forwardAction); //$NON-NLS-1$

actionBars.setGlobalActionHandler("stop", stopAction); //$NON-NLS-1$

actionBars.setGlobalActionHandler("refresh", refreshAction); //$NON-NLS-1$

return browser;

}

public Browser getBrowser(){

return browser;

}

}

thanks in advance again

moonnya at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 5
> then how to unset the null value of them?somevalueThatIsNull = newValue;If I really have to tell you I might ask you to stop coding right now and start learning the basics, like "what is a variable".
CeciNEstPasUnProgrammeura at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 6

> then how to unset the null value of them?

A better question might be "How do I figure out which variable is null?" In your

catch block try printing the value of site and site.getPage().

From the look of what you posted it appears that you expect that the site and

it's associated page do exist, and that the variables will, therefore, be

non-null. So in a sense the damage is already done, and you can't (sensibly)

"unset" them. Rather you should go back to whereever the null variable was

supposed to have got its value and see why it is null.

pbrockway2a at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...
# 7
public class WebBrowser extends ViewPart {public static final String ID_VIEW = "report.WebBrowser";1) what is ViewPart ?2) in your code u r concatinating two SQL statements, there is no seperator between two. might be there is a problem.
nikhil_shravanea at 2007-7-7 16:15:01 > top of Java-index,Java Essentials,Java Programming...