0

I'm Working on project and I have this problem:

The method setCategory(TypeCategory) in the type Client is not applicable for the arguments (String)

This is my code:

Enum class

public enum TypeCategory {
Private ,
Public ;
}

Bean class

public List<Client>getRessourcesList2s(){ 

        clientSk sk = new clientSk(2);
        ArrayList<Client> listeUsers= new  ArrayList<>();

    try {
                JSONArray json = clientSk.readJsonFromUrl("http://localhost:22033/API/Affichage");
                for (int i = 0, count = json.length(); i < count; i++) {
                    Client s = new  Client();
                JSONObject obj = (JSONObject)json.get(i);

               s.setCategory(obj.get("category").toString());

               listeUsers.add(s);

             }
                System.out.println(listeUsers);

            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        return (listeUsers);
    }   

My problem with this:

s.setCategory(obj.get("category").toString());

I don't know what to do ?

Ivar
  • 5,377
  • 12
  • 50
  • 56
DevCode
  • 23
  • 5

1 Answers1

-1

You can map a string to each and every enum if I understand the title correctly and Java will do the mappings. Let me know if that helps.

  • Thanks For Aswering ! But My Problem with this line s.setCategory(obj.get("category").toString()); it's wrong code and it's missing something ! – DevCode Jan 02 '19 at 12:17
  • 1
    Hi, I believe you didn't downvote, there are lot's of Douchbags over here who take care about their career and not about others hence they find out themselves at the 40th without job and without friends. Please use the suggestion in the answer, you need a mapping between enum and the string you are setting "As Category" to do that do enum... {Private("Private"), Public("Public")} with the proper rules of enum definitions and use Value Of. Thanks and take care until the wipe out my comment. – Vitali Pom Jan 06 '19 at 19:35