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]);
}
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) { } }
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ya i tried that also.. But i get the error on this line
Project proj=it.next();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because you need to say Iterator<Project>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Project proj=it.next();
Are u saying here to do the typecasting? How?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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... :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No idea. What error message are you getting?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.