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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:35:51+00:00 2026-05-28T01:35:51+00:00

public void buildArrayForMonth(int month, int year, int numOfDays, JSONArray array){ JSONObject[][] monthArray = null;

  • 0
public void buildArrayForMonth(int month, int year, int numOfDays, JSONArray array){
    JSONObject[][] monthArray = null;

    SimpleDateFormat monthFormat = new SimpleDateFormat("M");
    SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
    SimpleDateFormat dateFormat = new SimpleDateFormat("d");

    for(int i=0;i<array.length();i++){

        try {
            JSONObject event = array.getJSONObject(i);
            String date_full = event.getString("date_full");

            Date date = new Date(HttpDateParser.parse(date_full));
            int theMonth = Integer.parseInt(monthFormat.format(date)) - 1;
            int theYear = Integer.parseInt(yearFormat.format(date));
            int theDate = Integer.parseInt(dateFormat.format(date));

            if(theMonth == month && theYear == year){
                System.out.println("This Month" + date_full);
                monthArray[theDate][monthArray[theDate].length] = event; //add event object to the month array and its respective date

            }


        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }



}

I essentially want thedate to be an array containing JSONObjects. My app crashes with what I have now. I’m not sure if you’re able to do this. Does Java have anything like push or add?

  • 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-28T01:35:51+00:00Added an answer on May 28, 2026 at 1:35 am

    You forgot to create an array before initialize (I think you are getting NullPointerException in your sample code):

    monthArray = new JSONObject[32][32];
    

    Also, may be HashMap will be more useful for that task.

    UPD Ops, and one question, why do you need two dimensional array? I think one dimension is enough.

    JSONObject monthArray = new JSONObject[32];
    monthArray[theDate] = event
    

    UPD2 And I recommend to use Calendar instead of Date and SimpleDateFormat. It is more correct way, for example:

    Calendar c = Calendar.getCalendar();
    c.setTimeInMillis(HttpDateParser.parse(date_full));
    int theMonth = c.get(Calendar.MONTH);
    int theYear = c.get(Calendar.YEAR);
    int theDate = c.get(Calendar.DAY_OF_MONTH);
    

    UPD3

    Update after comments. If more than one event can occurs in one day then you have use HashMap with List as I proposed.

    HashMap<Integer, List<JSONObject>> monthArray = new HashMap<Integer, List>();
    ...
    if (...) {
        ...
        List l = monthArray.get(theDate);
        if (l == null) {
            l = new LinkedList<JSONObject>();
        }
    
        l.add(event);
    
        monthArray.put(theDate, l);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int
public void Draw(SpriteBatch theSpriteBatch) { Random rand = new Random(); for(int y = 0;
public void Insert(int value) { if (value < Data) { if (LeftNode == null)
public void sort() { datelist = new List<DateTime>(rdate); //timedates intlist = new List <Int>(rint);
public void Save() { XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation)); /* A first chance exception
[TestMethod] public void Memory() { var wr = new WeakReference(aaabbb); Assert.IsTrue(wr.IsAlive); GC.Collect(); GC.Collect(); GC.Collect();
[TestInitialize()] public void MyTestInitialize() { XmlTextWriter writer = new XmlTextWriter(DataFile.xml, Encoding.UTF8); writer.Formatting = Formatting.Indented;
public void ScoreFirstBall(int pinsKnockedDown) { if (IsStrike(Frame, pinsKnockedDown)) { Score = X; ScoreMessage =
public void onListItemClick(ListView parent, View v, int position, long id) { super.onListItemClick(parent, v, position,
public void createpass() { //set up dialog final Dialog dialog = new Dialog(App.this); dialog.setContentView(R.layout.createpass);

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.