I created an Integer array and I want to insert an index of a string;

indexes[i] = theText.indexOf(R.getString(0), i);

But I get an error about using indexOf.

How can I fix that?

*I can't change the array to int because I have a comparison of array index to null

Thanks!

share|improve this question

2  
But I get an error about using indexOf. > What was the error? Did it happen at compile time? run time? – coobird May 18 '11 at 9:30
1  
What error, and what's the type of theText? – Jon Skeet May 18 '11 at 9:31
If you epect an answer, you should provide more detailed information, like John Skeet said. – Sylar May 18 '11 at 9:50
feedback

3 Answers

up vote 0 down vote accepted

indexes is array of Integers? Maybe you are using Java 1.4. It doesn't support autoboxing. Try

indexes[i] = new Integer(theText.indexOf(R.getString(0), i));
share|improve this answer
feedback

theText.indexOf returns an int. You need to convert it to a string e.g.

indexes[i] = new Integer(theText.indexOf(R.getString(0), i));

Assumptions:

  1. indexes is an Integer[]
  2. theText IS-A String

This must be pre Java 5, otherwise autoboxing would convert the int returned by indexOf into its boxed Integer class.

share|improve this answer
1  
in the question is stated that it is an Integer array – Gabriel Ščerbák May 18 '11 at 9:36
feedback

If the only problem is in the type, you can use the Integer constructor: http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html#Integer(int)

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.