0

I have a method in an android application:

public void changeImageView (HashMap<String,String> Detail)

I have been trying to call this method in the onCreate method in the same class.

I have tried:

changeImageView();

and

changeImageView(HashMap<String,String> Detail);

Both of which give me errors. The first gives me an error stating that the parameters are missing - understandable. But when I try the second version, I get an error saying "expression expected" with HashMap<String,String>.

I am probably missing something very obvious and have been unable to find anything online that can answer my question.

4
  • 1
    You need to provide a HashMap<String,String> object. You can create an empty hash map with new HashMap<String,String>() Commented Apr 8, 2016 at 17:13
  • Try changeImageView(someMap); where someMap is declared as HashMap<String, String> Commented Apr 8, 2016 at 17:13
  • 1
    And being nothing but sincere, you need to go through a basic Java tutorial and/or read a good book on learning Java before continuing Android programming or you will be miserable. Commented Apr 8, 2016 at 17:15
  • Brilliant, thank you so much for your comments! codeMagic: I am working through a few exercises from text books. I'm struggling slightly but getting there! Thank you for your response :) Commented Apr 8, 2016 at 17:20

2 Answers 2

1

First, create an instance of HashMap<String, String>.

 Map<String, String> map = new HashMap<>();

After its filling or other operations on the map, pass it as a parameter to your method.

changeImageView(map);

I would suggest you reading about methods on Oracle Tutorials.

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

1 Comment

Thank you very much! I will accept your answer as soon as the 'time barrier' to accept lapses :)
1

HashMap is a collection class available in java.util package.

A method changeImageView() here has a definition which takes a HashMap object of type [Generic Type : Google it to know more about it].

You need to create a HashMap object :

Map<String,String> map=new HashMap<String,String>();

You can add values to the above hashmap as given below :

map.add("key1","value1");
map.add("key2","value3");

depending upon your requirements.

Now you can pass this map object to the changeImageView() method as given below:

changeImageView(map)

Seems like you are a newbie to Java and OOP , please refer any Java basic tutorials . This will help you to build up your basic concepts.

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.