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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:49:11+00:00 2026-05-24T20:49:11+00:00

I have the following class that doesn’t seem to be returning a List from

  • 0

I have the following class that doesn’t seem to be returning a List from the getter.

package springmvc.service;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

import springmvc.model.Brand;
import springmvc.model.Car;

public class CarManager {

    private static List<Car> carList;

    static {
        Brand brand1 = new Brand();
        brand1.setId((long) 1);
        brand1.setName("Mercedes");
        brand1.setCountry("Germany");

        Brand brand2 = new Brand();
        brand2.setId((long) 2);
        brand2.setName("Peugeot");
        brand2.setCountry("France");

        Car car1 = new Car();
        car1.setId((long) 1);
        car1.setBrand(brand1);
        car1.setModel("SL 500");
        car1.setPrice(new BigDecimal(40000));

        Car car2 = new Car();
        car2.setId((long) 2);
        car2.setBrand(brand2);
        car2.setModel("607");
        car2.setPrice(new BigDecimal(35000));

        carList = new LinkedList<Car>();
        carList.add(car1);
        carList.add(car2);
    }

    public List<Car> getCarList() {
        return carList;
    }
}

For the record, here is the Spring controller class where I’m calling the above class. All the statics are copied from the tutorial I got this from.

package springmvc.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import springmvc.service.CarManager;

public class CarListController implements Controller {
    public ModelAndView handleRequest(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {

        CarManager carManager = new CarManager();

        ModelAndView modelAndView = new ModelAndView("carList");
        modelAndView.addObject("carList", carManager.getCarList());

        return modelAndView;
    }
}

Here is what I have for spring-servlet.xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <bean name="/carList.jsp" class="springmvc.web.CarListController"/>
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>
  • 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-05-24T20:49:13+00:00Added an answer on May 24, 2026 at 8:49 pm

    Check your servlet container log for any exceptions being thrown. It could be throwing an exception in the static initialiser before it creates carList.

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

Sidebar

Related Questions

Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
In Java, assume I have the following class Container that contains a list of
I have the following code that doesn't compile. class Base { public: virtual ~Base()
I have a class that looks like the following: public class MyClass { private
We have a class a class that looks something like the following: public class
I have the following members defined in a class that I'm trying to deserialise:
I have the following ugly if statement that is part of a class that
Assume that we have the following code: class Program { static volatile bool flag1;
I have following code snippet that i use to compile class at the run
So I have a class that has the following member variables. I have get

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.