2017-09-20 3 views
0

Ich weiß, das ist wahrscheinlich ein einfaches Problem, aber ich bin verwirrt, warum meine ArrayAdapter nicht funktioniert. Ich bin mit Nachrüst-Daten zurückrufen, und ich bin die Daten zurück bekommen, aber wenn ich versuche, die Daten in eine ArrayAdapter ich folgende Fehlermeldung in ide erhalten hinzuzufügen:Problem beim Erstellen von 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>) 

Ich bin sicher, dass die Auflösung wahrscheinlich genau dort, aber ich kann es nicht sehen. Hier ist mein Code.

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; 

} 

Ich muss nur wissen, was ich das zu analysieren, bei dem Versuch, falsch zu machen Daten und bekommen es an die ListView übergeben.

Vielen Dank für Ihre Zeit und Unterstützung in dieser Angelegenheit.

+0

Was ist mit 'LogCat', hast du es? – Stanojkovic

+0

Ich bin nicht wirklich in der Lage mit diesem ArrayAdapter in meinem Code zu bauen. Das Build schlägt fehl und ich bekomme die obige Meldung von Gradle – mtrueblood

+0

Zeige Zeilen 49, 37. – Stanojkovic

Antwort

1

Aus dem Fehler:

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>) 

Der Konstruktor muss den letzten Parameter als int oder OpenPulls[] oder List<OpenPulls>. Aber Sie übergeben ein Objekt an den Konstruktor:

openpullsObject = response.body(); 

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

Also, müssen Sie die richtigen Parameter übergeben.

Verwandte Themen