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 8226419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:45:42+00:00 2026-06-07T15:45:42+00:00

I’ve a package named classes which includes x.java and y.java. x.java: public class x{

  • 0

I’ve a package named classes which includes x.java and y.java.
x.java:

public class x{
private int a;
private int b;
private String c;
private String d;
private String e;
private String f;
//And the fields are encapsulated.
}

y.java:

public class y{
private List<x> xs;
private int k1;
private int k2;
private String k3;
private String k4;
//And the fields are encapsulated.
}

z.JSP:

<%
usecase y = new y();
request.getSession().setAttribute("yy", y);
%>
<form action="aaa?id=1" method="POST">
            <td>
            <input type="text" name="bbb"/>
            </td>
            <td>
            <input type="text" name="ccc"/>
            </td>
            <td>
            <input type="submit" name="ddd"/>
            </td>
        </form>

aaa.java (Servlet – inside the processRequest):

PrintWriter out = response.getWriter();
    try {
        y yy = (y) request.getSession().getAttribute("yy");
        String id = request.getParameter("id");
        x s = new x();
        s.setC(request.getParameter("bbb"));
        b.setD(request.getParameter("ccc"));

        if ("1".equals(id)) {
            s.setE("l");
        } else if ("2".equals(id)) {
            s.setE("k");
        }

        yy.getXs().add(s);
        response.sendRedirect("z.jsp");
    } finally {
        out.close();
    }

Here’s the code. when I watch it with a breakpoint everything goes well, variables get their values. But in this line: yy.getXs().add(s); there’s an error and it doesn’t redirect. Would you please help me?

SOLUTION: replace private List<x> xs; with List<X> xs = new ArrayList<X>();. Thanks a lot.

  • 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-07T15:45:44+00:00Added an answer on June 7, 2026 at 3:45 pm

    A NullPointerException, most of the time, means that you’re dereferencing a null variable. I assume the line causing the exception (line 97 in z.java, as the stack trace indicates) is the following line:

    yy.getXs().add(s);
    

    Then it can mean two things:

    1. yy is null
    2. The list returned by yy.getXs() is null.

    Use a debugger to identify the problem, or add logging traces in your code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.