Welcome to Dream.In.Code
Become a Java Expert!

Join 150,422 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,099 people online right now. Registration is fast and FREE... Join Now!




null pointer exception

 
Reply to this topicStart new topic

null pointer exception

nila
3 Apr, 2008 - 09:29 PM
Post #1

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

Hi, i am getting the following error when i run my code.
I think i am using null where the object is required.but i dont know how to solve it.Anyone help me please.
CODE


public class OutboundServlet1 extends HttpServlet {
    private ManagerConnection managerConnection;
    protected AbstractMeetMeEvent abstractMeetme;
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    String exten = request.getParameter("extension");
    String agent = request.getParameter("agent");
    String meetMe="21045";
try {    
ManagerConnectionFactory factory = new ManagerConnectionFactory(
                    "localhost", "admin", "1234"); //
this.managerConnection = factory.createManagerConnection();

OriginateAction originateAction;
ManagerResponse originateResponse;
originateAction = new OriginateAction();
AgentCallbackLogin=new AgentCallbackLoginAction(agent,exten);            

originateAction.setChannel("local" + '/' + "5102");
originateAction.setContext("default");
originateAction.setExten(exten);
originateAction.setPriority(new Integer(1));    

originateAction.setTimeout(new Integer(30000));        

abstractMeetme.getMeetMe();            
managerConnection.login();
originateResponse = managerConnection.sendAction(originateAction,
                    30000);            

managerConnection.logoff();
out.println("OK");
        } catch (Exception e) {
            out.println("NOT OK");
            e.printStackTrace();
        }
    }
}

The following is the error.
QUOTE

java.lang.NullPointerException
at com.example.servlets.OutboundServlet1.doGet(OutboundServlet1.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)

User is offlineProfile CardPM
+Quote Post

bhandari
RE: Null Pointer Exception
4 Apr, 2008 - 12:10 AM
Post #2

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
QUOTE
String exten = request.getParameter("extension");
String agent = request.getParameter("agent");

AgentCallbackLogin=new AgentCallbackLoginAction(agent,exten);


Always check objects against null before using in program.

User is offlineProfile CardPM
+Quote Post

nila
RE: Null Pointer Exception
4 Apr, 2008 - 12:49 AM
Post #3

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

Thanks.But i ithink the error is due to the line
QUOTE

abstractMeetme.getMeetMe();

please tell me how to rectify that
User is offlineProfile CardPM
+Quote Post

bhandari
RE: Null Pointer Exception
4 Apr, 2008 - 01:15 AM
Post #4

D.I.C Addict
Group Icon

Joined: 31 Jan, 2008
Posts: 747


Dream Kudos: 900
My Contributions
QUOTE
But i ithink the error is due to the line


Why don't you debug your app to know the exact position of problem!!

User is offlineProfile CardPM
+Quote Post

1lacca
RE: Null Pointer Exception
4 Apr, 2008 - 01:32 AM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
If this is the full source, then abstractMeetme is not instantiated anywhere, so it is obviously null at that point.
User is offlineProfile CardPM
+Quote Post

nila
RE: Null Pointer Exception
4 Apr, 2008 - 01:43 AM
Post #6

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

if i instantiate the abstractMeetme like this:
QUOTE

abstractMeetme=new AbstractMeetMeEvent().

It is showing the following error:
QUOTE

Cannot instantiate the type AbstractMeetMeEvent


Am i wrong here.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Null Pointer Exception
4 Apr, 2008 - 02:24 AM
Post #7

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
From this much code it is hard to tell what are you up to.
I suppose there are two scenarios:
- you get that meetme object from somewhere
- you have to create it
I don't have a clue for the first one in your case, so let's look at the second one. Since it is an abstract class, you can not instantiate it. You should try to look for an extending class that is not abstract and instantiate that, or find a factory that has a static class that gets you an instance.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:25PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month