Jump to content
Changes to the Jaspersoft community edition download ×

JavaBeans DataSource problem???


Recommended Posts

By: sunlight - foundnothing

JavaBeans DataSource problem???

2006-03-02 22:06

I have some question when I set the JavaBeans as the DataSource

maybe I should describe the question as following:

(1)firstly,I will instruct the process how I did it.

I construct two class(Person and Factory) like this,

 

public class Person {

private String name = "";

private int age = 0;

public Person(String name,int age) {

this.name = name;

this.age = age;

}

public String getName(){

return name;

}

public int getAge(){

return age;

}

}

 

 

import java.util.Vector;

import java.util.Collection;

public class Factory {

public static Collection generateCollection(){

Vector collection = new Vector();

Person p;

try{

p = new Person("Tom",20);

collection.add(p);

p = new Person("Found",26);

collection.add(p);

p = new Person("Lucy",18);

collection.add(p);

p = new Person("Jame",35);

collection.add(p);

p = new Person("Smith",42);

collection.add(p);

}

catch(Exception e){

}

return collection;

}

}

 

(2)secondly,I use the command of javac to assemble Factory Class

as follows:

javac Factory.java

 

(3)then,I set up the Ireport classpath c:Ireportclasses which contains the two class

 

files

Factory.class and person.class

 

(4)I open the item Datasource in the menu of Ireport and choose JavaBeans set Datasource,

Name:JavaBeans

Factory Class:Factory

static method:generateCollection

and I select the radio Collection of javaBeans.

(5)I test the connection but it tell me Exception Null??? I don't know why???

(6)I registe the fileds name and age in the frame of Fields and

set name's type as String,age Integer.

(7)I open a new document and put two fileds. one is $F{name} and the other is $F{age},then

 

I open the query widown and click the JavaBean Datasource,set class name as

Factory,then I click Read javabeans attributes,but the filed name and age vanish

instancely,and it display the filed name as class,the field type as java.lang.object

but why???? maybe it's leaded by the Exception in(5)????but who can tell me the reason???

(8)I run the report,and it never throw an Exception ,but it displayed nothing.

 

who can give me a sample!!!?????

Link to comment
Share on other sites

  • 2 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...