Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:51:13+00:00 2026-06-06T03:51:13+00:00

I am using a Java Web Service for @WebService() public class myWebService { /**

  • 0

I am using a Java Web Service for

@WebService()
public class myWebService {

    /**
     * Web service operation
     */
    MyClass Obj ;

    @WebMethod(operationName = "webmethod1")
    @Oneway
    public void webmethod1(@WebParam(name = "serailNo") String serailNo) {

        obj = new MyClass();
        //do some operations on obj;

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "webmethod2")
    public void webmethod2() {

        //do some operations on obj after doing intial operations in web method1

    }
}

I am unable to access obj in webmethod2. It is getting a null pointer exception.
As a detail : I want to create a object . That object should be accessed across all web methods. In such a way webmethod1 will do intial operations on obj and followed web method2 will use the same obj.
How can i achieve this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:51:15+00:00Added an answer on June 6, 2026 at 3:51 am

    The reason you are getting a nullpointer is because the webservice is not stateful, i.e the object does not exist during the second call. It is possible to create a stateful webservice but that depends on the kind of webservice and server your running it on…

    As npinti mentioned you could send the object along with the service. Although that might not be favorable, e.g if the object is big.

    You could create a local cache on the server containing all the created objects by and mapping them with the serialNo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a Web service using Java and Spring-ws. It is working fine,
I am working on Java web service using TOMCAT server over secured connection(SSL). Client
I have created a simple web-service using Java. i want to load jars related
I am working on the Java web service and using Tomcat server. Since this
I am developing an application that calls a java web service (using Jersey1.8). I
I am using JBoss 4.0 for creating a simple Web Service using the @WebService
For a new project, we want to build a web service in Java using
I am consuming a webservice using my java web application.This returns a number of
I have a JAX-B java web service which I'm using to update a database.
I'm using eclipse and I have a java web service (rest jax-rs) I also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.