问题试图形成ArrayAdapter

问题描述:

我知道这可能是一个简单的问题,但我很困惑,为什么我的ArrayAdapter不工作。我使用改装回调的数据,我得到的数据备份,但是当我试图将其数据添加到ArrayAdapter我收到以下错误IDE:问题试图形成ArrayAdapter

Error:(49, 37) error: no suitable constructor found for ArrayAdapter(HomeActivity,int,OpenPulls) 
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable 
(argument mismatch; OpenPulls cannot be converted to int) 
constructor ArrayAdapter.ArrayAdapter(Context,int,OpenPulls[]) is not applicable 
(argument mismatch; OpenPulls cannot be converted to OpenPulls[]) 
constructor ArrayAdapter.ArrayAdapter(Context,int,List<OpenPulls>) is not applicable 
(argument mismatch; OpenPulls cannot be converted to List<OpenPulls>) 

我敢肯定,分辨率为大概就在那里,但我看不到它。这是我的代码。

HomeActivity.java

public class HomeActivity extends AppCompatActivity { 

    public CdenApi cdenAPI; 
    private ArrayAdapter<OpenPulls> openPullsAdapter; 
    public OpenPulls openpullsObject; 

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

    cdenAPI = ((MyApplication) this.getApplication()).getCdenAPI(); 

    cdenAPI.getOpenPulls(cdenAPI.REQ_WITH, cdenAPI.CONT_TYPE, 
      ((MyApplication) this.getApplication()).getAuthToken()) 
      .enqueue(new Callback<OpenPulls>() { 

       @Override 
       public void onResponse(Call<OpenPulls> call, Response<OpenPulls> response) { 
        if (response.isSuccessful()) { 
         openpullsObject = response.body(); 

         openPullsAdapter = 
           new ArrayAdapter<OpenPulls>(HomeActivity.this, 0, openpullsObject) { 
            @Override 
            public View getView(int position, 
                 View convertView, 
                 ViewGroup parent){ 
             Currentpull currentItem = openpullsObject.currentpulls.get(position); 

             if(convertView == null) { 
              convertView = getLayoutInflater() 
                .inflate(R.layout.join_pulls_item, null, false); 
             } 

             TextView pullTo = (TextView)convertView.findViewById(R.id.storeToJoinTV); 
             TextView pullFrom = (TextView)convertView.findViewById(R.id.storeFromJoinTV); 

             pullTo.setText(currentItem.to.toString()); 
             pullFrom.setText(currentItem.from.toString()); 

             return convertView; 
            } 
           }; 

         final ListView itemsList = (ListView) findViewById(R.id.openPullsLV); 
         itemsList.setAdapter(openPullsAdapter); 

         Toast.makeText(HomeActivity.this, "Pulls returned Home.", Toast.LENGTH_SHORT).show(); 
        } else { 
         Toast.makeText(HomeActivity.this, "Pulls not returned Home", Toast.LENGTH_SHORT).show(); 
        } 
       } 
       @Override 
       public void onFailure(Call<OpenPulls> call, Throwable t) { 
        t.printStackTrace(); 
       } 
      }); 

    } 

} 

OpenPulls.java

import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

public class OpenPulls { 

    @SerializedName("currentpulls") 
    @Expose 
    public ArrayList<Currentpull> currentpulls = null; 

    } 

Currentpull.java

import com.google.gson.annotations.Expose; 
import com.google.gson.annotations.SerializedName; 

public class Currentpull { 

    @SerializedName("id") 
    @Expose 
    public Integer id; 
    @SerializedName("created_at") 
    @Expose 
    public String createdAt; 
    @SerializedName("updated_at") 
    @Expose 
    public String updatedAt; 
    @SerializedName("pull_id") 
    @Expose 
    public Integer pullId; 
    @SerializedName("box_count") 
    @Expose 
    public Integer boxCount; 
    @SerializedName("status") 
    @Expose 
    public String status; 
    @SerializedName("total_quantity") 
    @Expose 
    public Integer totalQuantity; 
    @SerializedName("to") 
    @Expose 
    public String to; 
    @SerializedName("from") 
    @Expose 
    public String from; 

} 

我只需要知道我在试图解析做错了数据并将其传递给ListView

非常感谢您在这件事上的时间和协助。

+0

什么'LogCat',你有吗? – Stanojkovic

+0

我实际上不能用我的代码中的此ArrayAdapter构建。生成失败,我得到上述从摇篮 – mtrueblood

+0

显示线49中的信息,37 – Stanojkovic

从错误:

Error:(49, 37) error: no suitable constructor found for ArrayAdapter(HomeActivity,int,OpenPulls) 
constructor ArrayAdapter.ArrayAdapter(Context,int,int) is not applicable 
(argument mismatch; OpenPulls cannot be converted to int) 
constructor ArrayAdapter.ArrayAdapter(Context,int,OpenPulls[]) is not applicable 
(argument mismatch; OpenPulls cannot be converted to OpenPulls[]) 
constructor ArrayAdapter.ArrayAdapter(Context,int,List<OpenPulls>) is not applicable 
(argument mismatch; OpenPulls cannot be converted to List<OpenPulls>) 

的构造函数需要的最后一个参数为int或OpenPulls[]List<OpenPulls>。但你传递一个对象的构造器:

openpullsObject = response.body(); 

openPullsAdapter = new ArrayAdapter<OpenPulls>(HomeActivity.this, 0, 
          openpullsObject) {...} 

所以,你需要传递正确的参数。