2016-12-07 5 views
0

こんにちは私のコードを更新したばかりで、今は「すべて」うまく動作しています。接続があり、アイテムを受け取りました。MAPに追加したいのですが、誰かが私を助けますか?APIマップ/ HashMapから受信

public class MainActivity extends AppCompatActivity { 

    public static final String ENDPOINT_URL = "https://euw.api.pvp.net/"; 
    private TextView resultTv; 
    private GetwilliamData getwilliamData; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     Retrofit retrofit = new Retrofit.Builder().baseUrl(ENDPOINT_URL) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .build(); 

     getwilliamData = retrofit.create(GetwilliamData.class); 

     Button allbtn = (Button) findViewById(R.id.getallBtn); 
     allbtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       loadwilliam(); 
      } 

     }); 


     Button onebtn = (Button) findViewById(R.id.oneBtn); 
     onebtn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       loadwilliam(); 

      } 

     }); 

     resultTv = (TextView) findViewById(R.id.resultTV); 
    } 

    private void loadwilliam() { 
     Call<SummonerData> call = getwilliamData.all(); 
     call.enqueue(new Callback<SummonerData>() { 
      @Override 
      public void onResponse(Call<SummonerData> call, Response<SummonerData> response) { 
       System.out.println("HERE --------------------> " + call.request().url()); 
       SummonerData result = response.body(); 
       System.out.println("here ------------------------> " + response.body().getwilliam().getName()); 
       displayResult(result); 
      } 

      @Override 
      public void onFailure(Call<SummonerData> call, Throwable t) { 
       System.out.println("kdfsssssssssv -----------------> " + t.getMessage()); 
       System.out.println("HERE ---------------------> testing"); 
      } 
     }); 
    } 

    private void displayResult(SummonerData sd) { //throws java.lang.IllegalAccessException 

     if (sd != null) { 

      william r = sd.getwilliam(); 
      Map<String, Object> result = new HashMap<String, Object>(); 
      Field[] declaredFields = r.getClass().getDeclaredFields(); 
      for (Field field : declaredFields) { 
       // try { 
        //result.put(field.getName(), field.get(r)); 
        result.put(field.getName(), field.getName()); 
       result. 
      // } 
      // catch (IllegalAccessException e){ 
        result.put("Error", "reflection error"); 


      // } 
      } 
      System.out.println(("--------------------------> id: " + result.get("id"))); 
      resultTv.setText("id: " + result.get("id")); 

     } else { 
      resultTv.setText("Error asd"); 
     } 

    } 

} 

そのここでの問題

private void displayResult(SummonerData sd) { //throws java.lang.IllegalAccessException 

if (sd != null) { 

    william r = sd.getwilliam(); 
    Map<String, Object> result = new HashMap<String, Object>(); 
    Field[] declaredFields = r.getClass().getDeclaredFields(); 
    for (Field field : declaredFields) { 
     // try { 
      //result.put(field.getName(), field.get(r)); 
      result.put(field.getName(), field.getName()); 
     result. 
    // } 
    // catch (IllegalAccessException e){ 
      result.put("Error", "reflection error"); 


    // } 
    } 
    System.out.println(("--------------------------> id: " + result.get("id"))); 
    resultTv.setText("id: " + result.get("id")); 

} else { 
    resultTv.setText("Error asd"); 
} 

が、私はいくつかのテストを実行していたその動作していない/悪いコーディングを知っている...

エクストラ:

public class SummonerData { 
@SerializedName("william") 
@Expose 
    private william william; 
/** 
* 
* @return 
* The william 
*/ 
    public william getwilliam() { 
    return william; 
} 
/** 
* 
* @param william 
* The william 
*/ 
    public void setwilliam(william william) { 
    this.william = william; 
} 

SummonerData

ウィルあなたのattetionのためのIAM

public class william { 

@SerializedName("id") 
@Expose 
private Integer id; 
@SerializedName("name") 
@Expose 
private String name; 
@SerializedName("profileIconId") 
@Expose 
private Integer profileIconId; 
@SerializedName("summonerLevel") 
@Expose 
private Integer summonerLevel; 
@SerializedName("revisionDate") 
@Expose 
private long revisionDate; 

/** 
* 
* @return 
* The id 
*/ 
public Integer getId() { 
    return id; 
} 

/** 
* 
* @param id 
* The id 
*/ 
public void setId(Integer id) { 
    this.id = id; 
} 

/** 
* 
* @return 
* The name 
*/ 
public String getName() { 
    return name; 
} 

/** 
* 
* @param name 
* The name 
*/ 
public void setName(String name) { 
    this.name = name; 
} 

/** 
* 
* @return 
* The profileIconId 
*/ 
public Integer getProfileIconId() { 
    return profileIconId; 
} 

/** 
* 
* @param profileIconId 
* The profileIconId 
*/ 
public void setProfileIconId(Integer profileIconId) { 
    this.profileIconId = profileIconId; 
} 

/** 
* 
* @return 
* The summonerLevel 
*/ 
public Integer getSummonerLevel() { 
    return summonerLevel; 
} 

/** 
* 
* @param summonerLevel 
* The summonerLevel 
*/ 
public void setSummonerLevel(Integer summonerLevel) { 
    this.summonerLevel = summonerLevel; 
} 

/** 
* 
* @return 
* The revisionDate 
*/ 
public long getRevisionDate() { 
    return revisionDate; 
} 

/** 
* 
* @param revisionDate 
* The revisionDate 
*/ 
public void setRevisionDate(long revisionDate) { 
    this.revisionDate = revisionDate; 
} 

GetWilliamData

public interface GetwilliamData { 


@GET("api/lol/euw/v1.4/summoner/by-name/william?api_key=105bf501-8748-4e05-a913-ec570428375f") 
Call<SummonerData> all(); 

@GET("api/lol/{server}/v1.4/summoner/by-name/{name}?api_key=105bf501-8748-4e05-a913-ec570428375f") 
Call<william> select(@Path("name") String name); 

}

感謝。

答えて

0

これを試してみてください:

william r = sd.getwilliam(); 
    Map<String, Object> result = new HashMap<String, Object>(); 
    Field[] declaredFields = william.class.getDeclaredFields(); 
    for (Field field : declaredFields) { 
     try { 
      field.setAccessible(true); 
      result.put(field.getName(), field.get(r)); 
     } 
     catch (IllegalAccessException e){ 
      result.put("Error", "reflection error"); 


     } 
    } 
+0

どうもありがとうサー!それは魅力のように働いている! – William

+0

@Williamあなたの質問を解決した場合、この回答に合格とマークすることができます。 – SandeepGodara

+0

残念です!私はここに新しい!完了しました! Btwあなたは知っていますか?コードから画像を選んでイメージする方法を知っていますか? 私はRIOT APIでこれを使用しています。このようなマッチ履歴(http://image.prntscr.com/image/07df9147d46946d19ca9e3642046191c.png) のようにしたいと思います。私はこれを試しています: https://developer.riotgames.com/docs/static-data 開始方法はありませんか?.... それとも新しいトピックを開くべきですか? ありがとう! – William

関連する問題