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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:52:30+00:00 2026-06-08T08:52:30+00:00

Ok. A big newbee question here but I’ve been trying in vain to find

  • 0

Ok. A big newbee question here but I’ve been trying in vain to find a solution.

Using the examples I found here i was able to get a customdatasource working in my report.

But … the example uses this bit of code for the actual object pased as data

private Object[][] data =
  {
   {"Berne", new Integer(22), "Bill Ott", "250 - 20th Ave."},
   {"Berne", new Integer(9), "James Schneider", "277 Seventh Av."},
   {"Boston", new Integer(32), "Michael Ott", "339 College Av."},
   {"Boston", new Integer(23), "Julia Heiniger", "358 College Av."}, etc...

Unfortunately java won’t allow dynamically adding to that Object array and as the report data is always going to be dynamic, it becomes useless.

I’ve experimented with a custom data class with two elements that I add to an ArrayList like

ArrayList<myDataObject> a = new ArrayList<myDataObject>();

for(int x=0;x<5;x++){
    myDataObject myl = new myDataObject("asdasd",Integer.toString(x));
    a.add(myl);
}

But (here’s the newbee part) i can’t seem to figure out how to convert this to a simple Object[][] that jasper expects.

Here’s the data class I’m using

import java.util.ArrayList;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class CustomData implements JRDataSource {

    private Object data[][];
    private int index;


//    public CustomData(Object o[][]) {
//        index = -1;
//        this.data = o;
//    }
     public CustomData(ArrayList <Object> a) {
        index = -1;
        this.data = (Object)a.toArray();
    }

    public boolean next() throws JRException {
        index++;
        return (index < data.length);
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object getFieldValue(JRField field) throws JRException {
        Object value = null;
        String fieldName = field.getName();

        if ("aName".equals(fieldName)) {
            value = data[index][0];
        }
        else if ("aNumber".equals(fieldName)) {
            value = data[index][1];
        }

        return (String)value;
//        throw new UnsupportedOperationException("Not supported yet.");
    }

}

Any help would be great.

  • 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-08T08:52:32+00:00Added an answer on June 8, 2026 at 8:52 am

    Simply iterating through the list and adding it to the 2-dimensional array would come to mind:

    public static void main(String[] args) {
        ArrayList<MyDataObject> a = new ArrayList<MyDataObject>();
    
        for(int x=0;x<5;x++){
            MyDataObject myl = new MyDataObject("asdasd", Integer.toString(x));
            a.add(myl);
        }
    
        int aSize = a.size();
        Object[][] thingy = new Object[aSize][2];
        for(int i = 0; i < aSize; i++) {
            MyDataObject mdo = a.get(i);
            thingy[i][0] = mdo.getS();
            thingy[i][1] = mdo.getI();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question here. I'd like to be able to specify through data (i.e. an
this is probably a really stupid question, but I am big R newbie and.
Newbie question here. I'm trying to teach myself, and sometimes the solo route can
Im having a big headcache with a header design: Here the demo: http://jsfiddle.net/uGECm/ The
I've got a big solution with many projects in it. So when it builds
I'm just a hobbyist programmer, but I find that as my programs get longer
I got this big newbie question. When i try the following; the 'servlet' turns
Well it's kind of a newbie question but I think lots of people have
I'm a bit of a newbie to ActiveAdmin, and I'm trying to show big
Forgive me if this is a newbie question, but... When playing video, is it

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.