Java Casting Object to Type?
<p>I want to select the items in the JList specific to what the patient already clicked. If I click on the 3rd patient, the JList will select the items that patient selected.</p>

<p>In the PatientConList are the condition objects for that patient.</p>

<p><strong>When you add a patient you do this:</strong></p>

<pre><code>List PatientConditions1 = new ArrayList();
PatientConditions1 =  ConditionsJList.getSelectedValuesList();
</code></pre>

<p><strong>Then when you click on a patient it does this</strong></p>

<pre><code>public void MakePatientJListSelected(ArrayList PatientConList) {
    //this makes selected, so get condition array off patient.
    //so call this from patient jlist listener
    ConditionsJList.clearSelection();
    //get number - 1, so then 0 = first
    ArrayList&lt;Conditions&gt; PassedIn = PatientConList;
    ArrayList SelectList = new ArrayList();

    for(Conditions p: PassedIn)
    {
       int Num = p.getNumber();
       Num = Num - 1;
       SelectList.add(Num);
    }    

    //int startSel = 0;
    //int endSel = 0;
    //ConditionsJList.setSelectionInterval(startSel, endSel);

    for(int k=0;k&lt;PassedIn.size();k++)
    {
        int startSel2 = k;
        int endSel2 = k;
        ConditionsJList.addSelectionInterval(startSel2, endSel2);
    }    
}
</code></pre>

<p>Sorry, Basically I have a JList and you can select the conditions you want and click add. this adds the list of conditions to the patient.</p>

<p>Basically when you select a patient to view I want it so that the jlist conditions for that patient are selected on the jlist.</p>

<p>Im getting this error Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to DentistAppNew.Conditions</p>

<p>My patient class:</p>

<pre><code>import java.util.*;

public class Patient {

private int AccountNumber;
private String Name;
private int Age;
private String Address;
private String  Sex;
private String Phone;
private List&lt;Conditions&gt; ConditionNames;

public Patient( int AccountNumber1,
                String Name1, 
                int Age1, 
                String Address1, 
                String Sex1, 
                String Phone1, 
                List&lt;Conditions&gt; ConditionNames1)
{                
    this.AccountNumber = AccountNumber1;
    this.Name = Name1;
    this.Age = Age1;
    this.Address = Address1;
    this.Sex = Sex1;
    this.Phone = Phone1;
    this.ConditionNames = ConditionNames1
}

public  int getAccountNumber() { return AccountNumber; }

public  String getName() { return Name; }

public int getAge() { return Age; }

public String getAddress() { return Address; }

public String getSex() { return Sex; }

public String getPhone() { return Phone; }

public List getConditionsList() { return ConditionNames; }

public  void setName(String Name1) { this.Name = Name1; }

public void setAge(int Age1) { this.Age = Age1; }

public void setAddress(String Address1) { this.Address = Address1; }

public void setSex(String Sex1) { this.Sex = Sex1; }

public void setPhone(String Phone1) { this.Phone = Phone1; }

}
</code></pre>

<p>my conditions class:</p>

<pre><code>public class Conditions {

    private int Number;
    private String Name;

    public Conditions( int Number1,String Name1) {
        this.Number = Number1;
        this.Name = Name1;      
    }   

    public  int getNumber() {
        return Number;
    }

    public  String getName() {
        return Name;
    }   
}
</code></pre>
