Skip to Content
0
Former Member
Jun 30, 2014 at 12:40 PM

java.lang.NullPointerException

277 Views

Hi Gurus,

I am working on an application where i need to display data from the portal database, on the basis of inputs given by the user; while doing so I am getting Null Pointer Exception. below is my code.

// ---------------------------------------------------------------------------

// This file has been generated partially by the Web Dynpro Code Generator.

// MODIFY CODE ONLY IN SECTIONS ENCLOSED BY @@begin AND @@end.

// ALL OTHER CHANGES WILL BE LOST IF THE FILE IS REGENERATED.

// ---------------------------------------------------------------------------

package com.lanco;

//

// IMPORTANT NOTE:

// _ALL_ IMPORT STATEMENTS MUST BE PLACED IN THE FOLLOWING SECTION ENCLOSED

// BY @@begin imports AND @@end. FURTHERMORE, THIS SECTION MUST ALWAYS CONTAIN

// AT LEAST ONE IMPORT STATEMENT (E.G. THAT FOR IPrivateZhse_displayView).

// OTHERWISE, USING THE ECLIPSE FUNCTION "Organize Imports" FOLLOWED BY

// A WEB DYNPRO CODE GENERATION (E.G. PROJECT BUILD) WILL RESULT IN THE LOSS

// OF IMPORT STATEMENTS.

//

//@@begin imports

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.Statement;

import com.lanco.wdp.IPrivateZhse_displayView;

import com.sap.tc.webdynpro.progmodel.api.WDVisibility;

//@@end

//@@begin documentation

//@@end

public class Zhse_displayView

{

/**

* Logging location.

*/

private static final com.sap.tc.logging.Location logger =

com.sap.tc.logging.Location.getLocation(Zhse_displayView.class);

static

{

//@@begin id

String id = "$Id$";

//@@end

com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);

}

/**

* Private access to the generated Web Dynpro counterpart

* for this controller class. </p>

*

* Use <code>wdThis</code> to gain typed access to the context,

* to trigger navigation via outbound plugs, to get and enable/disable

* actions, fire declared events, and access used controllers and/or

* component usages.

*

* @see com.lanco.wdp.IPrivateZhse_displayView for more details

*/

private final IPrivateZhse_displayView wdThis;

/**

* Root node of this controller's context. </p>

*

* Provides typed access not only to the elements of the root node

* but also to all nodes in the context (methods node<i>XYZ</i>())

* and their currently selected element (methods current<i>XYZ</i>Element()).

* It also facilitates the creation of new elements for all nodes

* (methods create<i>XYZ</i>Element()). </p>

*

* @see com.lanco.wdp.IPrivateZhse_displayView.IContextNode for more details.

*/

private final IPrivateZhse_displayView.IContextNode wdContext;

/**

* A shortcut for <code>wdThis.wdGetAPI()</code>. </p>

*

* Represents the generic API of the generic Web Dynpro counterpart

* for this controller. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;

/**

* A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>

*

* Represents the generic API of the Web Dynpro component this controller

* belongs to. Can be used to access the message manager, the window manager,

* to add/remove event handlers and so on. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;

public Zhse_displayView(IPrivateZhse_displayView wdThis)

{

this.wdThis = wdThis;

this.wdContext = wdThis.wdGetContext();

this.wdControllerAPI = wdThis.wdGetAPI();

this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

wdContext.currentContextElement().setVa_EPC(WDVisibility.NONE);

//@@end

}

//@@begin javadoc:wdDoExit()

/** Hook method called to clean up controller. */

//@@end

public void wdDoExit()

{

//@@begin wdDoExit()

try

{

conn.close();

}

catch(Exception eg)

{

eg.printStackTrace();

}

//@@end

}

//@@begin javadoc:wdDoModifyView

/**

* Hook method called to modify a view just before rendering.

* This method conceptually belongs to the view itself, not to the

* controller (cf. MVC pattern).

* It is made static to discourage a way of programming that

* routinely stores references to UI elements in instance fields

* for access by the view controller's event handlers, and so on.

* The Web Dynpro programming model recommends that UI elements can

* only be accessed by code executed within the call to this hook method.

*

* @param wdThis Generated private interface of the view's controller, as

* provided by Web Dynpro. Provides access to the view controller's

* outgoing controller usages, etc.

* @param wdContext Generated interface of the view's context, as provided

* by Web Dynpro. Provides access to the view's data.

* @param view The view's generic API, as provided by Web Dynpro.

* Provides access to UI elements.

* @param firstTime Indicates whether the hook is called for the first time

* during the lifetime of the view.

*/

//@@end

public static void wdDoModifyView(IPrivateZhse_displayView wdThis, IPrivateZhse_displayView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

//@@end

}

//@@begin javadoc:database()

/** Declared method. */

//@@end

public void database( )

{

//@@begin database()

Connection conn=null;

Statement sqlstat=null;

try

{

//data base connection statements, organise importa, jar files in navigator

Class.forName("oracle.jdbc.driver.OracleDriver");

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

conn =DriverManager.getConnection(connectiontext,user,pwd);

Statement stmt=conn.createStatement();

sql1= conn.createStatement();

}

catch (Exception e)

{

// TODO: handle exception

wdComponentAPI.getMessageManager().reportException("Error in database Method",true);

wdComponentAPI.getMessageManager().reportException(e.toString(),false);

}

//@@end

}

//@@begin javadoc:onActiondisplay(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActiondisplay(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActiondisplay(ServerEvent)

IPrivateZhse_displayView.IContextElement ele = wdContext.currentContextElement();

IPrivateZhse_displayView.IKeyElement key = wdContext.currentKeyElement();

wdContext.nodeKey().invalidate();

String Queryselect=null;

if(ele.getBusiness_group() == null|| ele.getBusiness_vertical() == null ||ele.getYear() == null){

wdComponentAPI.getMessageManager().reportException("* All Values are Mandatory",true);

}

else{

try{

//wdContext.nodeAmarkantak().invalidate();

//wdContext.nodeAnpara().invalidate();

//wdContext.nodeUdipi().invalidate();

database();

Statement stmt=conn.createStatement();

Queryselect="select key1, key2, key3, key4, key5 from hsemonthly_report1";

//

// wdComponentAPI.getMessageManager().reportException(Queryselect1,true);

ResultSet RST= stmt.executeQuery(Queryselect);

int count=0;

while(RST.next())

{

count=1;

//wdComponentAPI.getMessageManager().reportSuccess("going inside");

key.setKey1(RST.getString(1));

key.setKey2(RST.getString(2));

key.setKey3(RST.getString(3));

key.setKey4(RST.getString(4));

key.setKey5(RST.getString(5));

}

if(count ==1){

wdContext.currentContextElement().setVa_EPC(WDVisibility.VISIBLE);

}else{

wdContext.currentContextElement().setVa_EPC(WDVisibility.VISIBLE);

// wdContext.currentContextElement().setVa_visible_amrk(WDVisibility.NONE);

// wdContext.currentContextElement().setVa_visible_anpara(WDVisibility.NONE);

// wdContext.currentContextElement().setVa_visible_udipi(WDVisibility.NONE);

wdComponentAPI.getMessageManager().raiseException("No values exists for the selected date",true);

}

}catch(Exception e){

wdComponentAPI.getMessageManager().raiseException(e.toString(),true);

wdContext.currentContextElement().setVa_EPC(WDVisibility.VISIBLE);

// wdContext.currentContextElement().setVa_visible_amrk(WDVisibility.NONE);

// wdContext.currentContextElement().setVa_visible_anpara(WDVisibility.NONE);

// wdContext.currentContextElement().setVa_visible_udipi(WDVisibility.NONE);

}

try{

conn.close();

}

catch(Exception eg)

{

eg.printStackTrace();

}

}

//@@end

}

/*

* The following code section can be used for any Java code that is

* not to be visible to other controllers/views or that contains constructs

* currently not supported directly by Web Dynpro (such as inner classes or

* member variables etc.). </p>

*

* Note: The content of this section is in no way managed/controlled

* by the Web Dynpro Designtime or the Web Dynpro Runtime.

*/

//@@begin others

String connectiontext="jdbc:oracle:thin:@lepdb.lancogroup.net:1527:LEP";

String user="epuser";

String pwd="userep51";

// String connectiontext="jdbc:oracle:thin:@leapepdv.lancogroup.net:1527:LED";

// String user="epuser";

// String pwd="userep21";

//String Userid=null;

Connection conn=null;

Statement stmt=null;

Statement sql1=null;

Statement sql2= null;

//@@end

}

help me out with this issue