Error for jira project

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

No idea. What error message are you getting?

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

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.

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());

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

Project proj=it.next();

Because you need to say Iterator<Project>

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

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.

Project proj=it.next();

Are u saying here to do the typecasting? How?

@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 ...

@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... :-)

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) {
               
            }
        }

Suggest an answer

Log in or Sign up to answer
Community showcase
Published 14 hours ago in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

166 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you