0

having a bit of a spanner moment. I need to convert a List to String Array:

List<String> selectedIndicie to String[] targetIndices;

The selectedIndicie list is pulled from a backing bean and I attempt to convert it to a String array like so:

setTargetIndices(initialiseBean.getSelectedIndicie().toArray(getTargetIndices())); 

But Java has a right old moan saying:

An error occurred performing resource injection on managed bean searchBean

As I said I am having a spanner moment on how else to convert the List of Strings to an array of String so any suggests would be lovely.

Cheers

4
  • Can you split the line up a bit and see exactly which call is failing? Commented Aug 4, 2011 at 17:31
  • "An error occurred performing resource injection on managed bean searchBean". Please read the server logs for the entire stacktrace with the root cause. It contains your answer. Commented Aug 4, 2011 at 17:33
  • Are you doing that in the constructor? If so try moving it to a method with @PostConstruct. Commented Aug 4, 2011 at 17:34
  • @BalusC: Once I had similar kind of message. Now, I remember that actually I was trying to use EJB in the ManagedBean constructor. That was a different case. Commented Aug 4, 2011 at 17:45

3 Answers 3

1

List.toArray returns an array of Objects, which is likely to result in an exception when you execute setTargetIndices for this method would be accepting an array of String objects. The answer is to not convert the setter to accept an array of Object (for the JSF runtime might simply fail to recognize the setter as belonging to the targetIndices property), rather it is to invoke the setter with an array of Strings.

Sign up to request clarification or add additional context in comments.

2 Comments

spanner moment over: String[] targetIndices = initialiseBean.getSelectedIndicie().toArray(new String[0]);
I was wondering how you managed to get past a compiler error, and was about to delete this answer.
0

As I said I am having a spanner moment on how else to convert the List of Strings to an array of String so any suggests would be lovely.

Use the toArray method.

Comments

0

try this:

String[] targetIndices = selectedIndicie.toArray(new String[selectedIndicie.size()]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.