0

Pretty new in java. Very simple issue here but really don't understand whats the problem...

I have an array with strings. The array elements are url images. I have a view element which is changing the images. What I need is to set the image with an element from the array.

imageSwitcher.setImageUrl(Last_images[1].toString());
                Log.d("D1",Last_images[1].toString());

In the first line if I give it for example "www.example.com/1.jpg" its working. However when I give it the array element its not working. In the log.cat its showing the right url...

In the onCreate I have : Last_images = new String[10]; and in the class values I have : String[] Last_images = null;

Coming from PHP and I'm really confused why it is not working and I really think its something easy.

3
  • There is only a method ImageSwitcher.setImageURI. What is your imageSwitcher class? Commented Jun 21, 2013 at 7:45
  • Even Last_images[1] will do , toString() is redundant . What is the issue ? What is the content of Last_images[1] ? Pointer, an array with 10 elements will be indexed from 0 to 9. Commented Jun 21, 2013 at 7:46
  • Just avoid calling toString when the Object is actually a String. Commented Jun 21, 2013 at 7:46

4 Answers 4

1

Last_images may be null: in my opionion you should do something like that:

 if (Last_images != null && Last_images[i] != null) {
     imageSwitcher.setImageUrl(Last_images[1]);
 }
Sign up to request clarification or add additional context in comments.

Comments

1

Not clear from your question . But just some guess

If you are trying to access the first element of array luse Last_images[0]. And there is no need to use toString method ( no harm either).

If this is not the cases Then I would like to see the codes related to the assignment of the array.

Comments

0

Try to use

imageSwitcher.setImageURI(Uri.parse(Last_images[1]));

Comments

0

According to the Android Documentation, http://developer.android.com/reference/android/widget/ImageSwitcher.html, the class ImageSwitcher has a setImageURI(Uri uri) method. To create Uri objects, simply call Uri.parse(String myString).

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.