Error for jira project

xavier jir March 6, 2012

Hi i try to run the following code..But it shows the error.. Please guide what is the actual error how to resolve it??

ComponentManager cm=ComponentManager.getInstance();

ProjectManager pm = cm.getProjectManager();

List pro=new ArrayList<Project>();

pro.add(pm.getProjectObjects());

Iterator it=pro.iterator();

while(it.hasNext())

{

Project proj=it.next();

//id[i]=proj.getId();

//System.out.println(id[i]);

}

3 answers

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

xavier

Please try the following variants. After that, you will have to promise to read some Java tutorial. From the start, I didn't compile them so the eventual errors will need to be fixed by you.

ProjectManager pm = ComponentManager.getInstance().getProjectManager();

        List<Project> pro = pm.getProjectObjects();

        if(pro != null) {
            Iterator<Project> it=pro.iterator();
            
            while(it.hasNext()) {
                Project proj=it.next();
            }
        }

or better, the equivalent:

List<Project> pro = ComponentManager.getInstance().getProjectManager().getProjectObjects();

        if(pro != null) {
            for(Project proj : pro) {
               
            }
        }

0 votes
Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

Well, this is nice.

Line: pro.add(pm.getProjectObjects());

you are adding a list of projects as a reference into a list of projects. This is wrong.

It will die the first time you are taking the project because instead of projects, it has a single element which is a list of project, therefore error (class cast)

You should write:

pro = pm.getProjectObjects();

or

pro.addAll(pm.getProjectObjects());

xavier jir March 6, 2012

Ya i tried that also.. But i get the error on this line

Project proj=it.next();

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

Because you need to say Iterator<Project>

xavier jir March 6, 2012

The same error for this line

Project proj=it.next();

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Compilation failure

C:\service\src\main\java\com\example\plugin\tutorial\MyPlugin.java:[39,20] incompatible types

found : java.lang.Object

required: com.atlassian.jira.project.Project

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

Ohh, I hadn't spotted that your code was adding a list to a list like Radu has pointed out.

I think you might want to check the API docs for the version of Jira you are coding for, as well as following Radu's advice. Off the top of my head, getProjectObjects returns a set of generic objects in older versions (like the one I'm currently coding for), and not a set of Project objects. If I'm right on this, then your code is expecting a project object on the left hand of the "=" and the right hand side is getting a plain object. I don't know if a simple cast of types is the right thing to do.

xavier jir March 6, 2012

Project proj=it.next();

Are u saying here to do the typecasting? How?

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

@Nic Well, beginners mistakes are the most fun...Once he will figure out to template the list and the iterator he will be fine :)

Damn, I miss the C++ templates! When the language made a real difference between programmers ...

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

@Radu - I always try not to hand out answers on a plate because looking it up helps people learn for themselves. In this case, I don't even know if a cast is the correct thing to do! (I'm not a real coder). So I'm certainly not going to hand over code that might be bad practice... :-)

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

No idea. What error message are you getting?

xavier jir March 6, 2012

The following error i'm getting.. If you get solution means please share...

[ERROR] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Compilation failure

C:\service\src\main\java\com\example\plugin\tutorial\MyPlugin.java:[39,20] incompatible types

found : java.lang.Object

required: java.lang.Long

Radu Dumitriu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2012

For sure Nic has some crystal ball to see the line 39, column 20 in MyPlugin.java. I suggest you to read first some Java tutorial.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events