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

  • Home
  • SEARCH
  • 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 8934899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:52:47+00:00 2026-06-15T09:52:47+00:00

I am using WDCalendar in Struts2. I was converting Hashmap to Json String using

  • 0

I am using WDCalendar in Struts2.
I was converting Hashmap to Json String using GSON, but all of a sudden, i am getting NULL pointer exception while conveting Hashmap to JSON String

result = new Gson().toJson(ret);

My Code :

public static String loadAllEvents(String start, String end) throws SQLException {
        PreparedStatement ps1 = null;
        ResultSet rs1 = null;
        Gson gson = new Gson();
        String result = "";
        Connection con = ULDBConnectionUtility.getDBConnection();
        HashMap<String, Object> ret = new HashMap<String, Object>();




        try{
            String strSql = "SELECT * FROM EVENT_MANAGER";// WHERE START_DATE BETWEEN '"+start+"' AND '"+end+"'";           
            ps1 = con.prepareStatement(strSql);
            rs1  = ps1.executeQuery();

            SimpleDateFormat fromDB = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            java.text.SimpleDateFormat sourceFormat = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss ZZZ");


            ArrayList<ArrayList> eventArrayList = new ArrayList<ArrayList>();
            while(rs1.next()){              
                ArrayList EvtData = new ArrayList();
                EvtData.add(rs1.getInt("EVENT_ID"));//0
                EvtData.add(rs1.getString("EVENT_TITLE"));//1
                EvtData.add(sourceFormat.format(fromDB.parse(rs1.getString("START_DATE"))));//2
                EvtData.add(sourceFormat.format(fromDB.parse(rs1.getString("END_DATE"))));//3
                EvtData.add(rs1.getInt("IS_ALL_DAY_EVENT"));//4
                EvtData.add(Integer.parseInt("0"));//5
                EvtData.add(rs1.getInt("RECURRING_RULE"));//6
                EvtData.add(rs1.getString("COLOR"));//7
                EvtData.add(Integer.parseInt("1"));//8
                EvtData.add(rs1.getString("LOCATION"));//9
                EvtData.add("");//10
                eventArrayList.add(EvtData);
            }
            String error = "";
             ret.put("events", eventArrayList);
             ret.put("issort", true);
             ret.put("start", sourceFormat.format(fromDB.parse(start)));
             ret.put("end", sourceFormat.format(fromDB.parse(end)));
             ret.put("error", error);
             System.out.println("ret : "+ret);
             result = new Gson().toJson(ret);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs1 != null) {
                    rs1.close();
                }
                if (ps1 != null) {
                    ps1.close();
                }
                if (con != null) {
                    con.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return result;
    }

HashMap before passing to convertion:

{events=[[98, EvebtTitle, Mon Dec 03 2012 10:45:00 +0530, Wed Oct 17 2012 11:15:00 +0530, 0, 0, 0, 0, 1, NJ, ], [118, testDec, Wed Dec 05 2012 09:00:00 +0530, Wed Dec 05 2012 10:00:00 +0530, 0, 0, 0, null, 1, null, ], [67, Test45, Wed Dec 05 2012 10:30:00 +0530, Tue Oct 16 2012 11:00:00 +0530, 1, 0, 0, 0, 1, NY, ], [119, sd, Tue Dec 04 2012 00:00:00 +0530, Tue Dec 04 2012 00:00:00 +0530, 1, 0, 0, null, 1, null, ], [78, Test, Fri Dec 07 2012 09:30:00 +0530, Mon Oct 15 2012 10:15:00 +0530, 0, 0, 0, 1, 1, LA, ], [66, Event 2, Tue Dec 04 2012 10:00:00 +0530, Tue Oct 16 2012 10:30:00 +0530, 0, 0, 1, 0, 1, CA, ]], start=Thu Jan 01 1970 05:30:00 +0530, issort=true, end=Thu Jan 01 1970 05:30:00 +0530, error=null}

Error:

20:49:15,597 ERROR [STDERR] java.lang.NullPointerException
20:49:15,599 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:443)
20:49:15,601 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:430)
20:49:15,604 ERROR [STDERR]     at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:128)
20:49:15,605 ERROR [STDERR]     at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:96)
20:49:15,606 ERROR [STDERR]     at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:47)
20:49:15,608 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:445)
20:49:15,609 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.serialize(DefaultTypeAdapters.java:430)
20:49:15,610 ERROR [STDERR]     at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:128)
20:49:15,611 ERROR [STDERR]     at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:96)
20:49:15,612 ERROR [STDERR]     at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:47)
20:49:15,613 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.serialize(DefaultTypeAdapters.java:509)
20:49:15,613 ERROR [STDERR]     at com.google.gson.DefaultTypeAdapters$MapTypeAdapter.serialize(DefaultTypeAdapters.java:489)
20:49:15,614 ERROR [STDERR]     at com.google.gson.JsonSerializationVisitor.visitUsingCustomHandler(JsonSerializationVisitor.java:128)
20:49:15,615 ERROR [STDERR]     at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:96)
20:49:15,616 ERROR [STDERR]     at com.google.gson.JsonSerializationContextDefault.serialize(JsonSerializationContextDefault.java:47)
20:49:15,617 ERROR [STDERR]     at com.google.gson.Gson.toJson(Gson.java:269)
20:49:15,618 ERROR [STDERR]     at com.google.gson.Gson.toJson(Gson.java:220)
20:49:15,618 ERROR [STDERR]     at com.google.gson.Gson.toJson(Gson.java:200)
20:49:15,619 ERROR [STDERR]     at dao.UtilityDao.loadAllEvents(UtilityDao.java:174)
20:49:15,620 ERROR [STDERR]     at utility.CalendarUtility.loadAllList(CalendarUtility.java:64)
20:49:15,621 ERROR [STDERR]     at servlet.DataFeed.doGet(DataFeed.java:56)
20:49:15,622 ERROR [STDERR]     at servlet.DataFeed.doPost(DataFeed.java:97)
20:49:15,623 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
20:49:15,624 ERROR [STDERR]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
20:49:15,625 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
20:49:15,626 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
20:49:15,627 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
20:49:15,
  • 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-15T09:52:48+00:00Added an answer on June 15, 2026 at 9:52 am

    solved:

    Some of the events field values were NULL in DB and this was the Cause.

    In ret.put("events", eventArrayList);

    eventArrayList refers ArrayList<ArrayList> and few field values in <ArrayList> were NULL,

    From above Ex: (Look into the Null value in inner arraylist which is at second index)

    {events=[[98, EvebtTitle, Mon Dec 03 2012 10:45:00 +0530, Wed Oct 17 2012 11:15:00 +0530, 0, 0, 0, 0, 1, NJ, ], [118, testDec, Wed Dec 05 2012 09:00:00 +0530, Wed Dec 05 2012 10:00:00 +0530, 0, 0, 0, null, 1, null, ]]}
    

    After removing the Null values from the inner ArrayList things are working fine.

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

Sidebar

Related Questions

Using server-side C#, how can I convert a querystring to a JSON string of
Using JNotify in project and it fulfill my all requirements, but some times it
Using the Redis info command, I am able to get all the stats of
Using import datetime in python, is it possible to take a formatted time/date string
using a binary search tree I need to add to a vector all int
Using Yii, I want to delete all the rows that are not from today.
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using the HTML5 File API I can get the Binary String representation of a
Using NSDateComponents I know how to get the day component, but this gives me

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.