Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:10:25+00:00 2026-06-10T09:10:25+00:00

I have an odd (in my mind) problem. I am currently making a Custom

  • 0

I have an odd (in my mind) problem. I am currently making a Custom JComboBoxModel for some custom functionality I need from a Custom Renderer I am not yet certain how to deal with, I will post regarding that later.

Regardless, as the Title suggested I am getting some Type errors.

Here is the classes (current) code:

package miscclasses;
import java.util.ArrayList;
import javax.swing.AbstractListModel;

public class CustomComboBoxModel<String> extends AbstractListModel<String> {
    /**
     * Contains a list of row indexes that shouldn't be displayed.
     */
    private ArrayList<String> alreadySelectedIndexes;
    /**
     * The comboBoxes selected index.
     */
    private int selectedIndex=-1;
    /**
     * Contains a list of values in this model.
     */
    private ArrayList<String> vals;
    /**
     * Creates an empty CustomComboBoxModel.
     */
    public CustomComboBoxModel() {
        this.alreadySelectedIndexes=new ArrayList<>();
        this.vals = new ArrayList<>();
    }
    /**Creates a CustomComboBoxModel with the values passed in.
     * 
     * @param values the row values.
     */
    public CustomComboBoxModel(ArrayList<String> values) {
        this();
        this.vals.addAll(values);
    }

    public CustomComboBoxModel(ArrayList<String> values, ArrayList<String> alreadySelected) {
        this(values);
        this.alreadySelectedIndexes.addAll(alreadySelected);
    }

    public CustomComboBoxModel(ArrayList<String> values, ArrayList<String> alreadySelected, int selectedIndex) {
        this(values, alreadySelected);
        this.selectedIndex=selectedIndex;
    }

    public CustomComboBoxModel(ArrayList<String> values, ArrayList<String> alreadySelected, String selectedValue) {
        this(values, alreadySelected);
        if(!this.vals.isEmpty()) {
            //this.selectedIndex = Misc.containsI(this.vals, selectedValue);
        }
    }

    @Override
    public int getSize() {
        return this.vals.size();
    }

    @Override
    public String getElementAt(int i) {
        return this.vals.get(i);
    }

    public boolean isRowSelected(int i) {
        return ((!this.alreadySelectedIndexes.contains(Integer.toString(i)))?false:true);
    }
}

The error I am receiving is on line 55 where I attempt to get the selected values index. This is the commented line in the constructor that accepts two ArrayList lists and a String value. The error states that there is “no suitable method for containsI(java.util.ArrayList,String) method miscclasses.Misc.containsI(java.util.ArrayList, java.lang.String) is not applicable”.

So far as I know String and java.lang.String are the exact same thing. As such I cannot seem to figure out what could cause this issue, and thought I would come to ask those more knowledgeable in the ways of Code-fu than I.

For reference, the Misc.containsI(ArrayList,String) code is here:

 /**
 * Finds the index of value Target. Returns -1 if this ArrayList doesn't contain Target.
 * @param a         ArrayList of Strings a.
 * @param target    Value to find.
 * @return          Index of target if found; Else returns -1.
 */
public static int containsI(ArrayList<String> a, String target) {
    for (int i = 0; i < a.size(); i++)
    {
        if(a.get(i).equalsIgnoreCase(target))
            return i;
    }
    return -1;
}

I am also strangely receiving the following warning in my isRowSelected(int i) function:
“Suspcious call to java.util.Collection.contains: Expected type String, actual type String”.

Again, I don’t understand why I am getting warning. It seems to be entirely valid code, and I have done similar before. Any help with this odd warning and error, would be much appreciated.

EDIT: Changing the Declaration so it reads:

public class CustomComboBoxModel extends AbstractListModel<String>

instead of:

public class CustomComboBoxModel<String> extends AbstractListModel<String>

Appears to have gotten rid of the warning and error. I do not understand why however, as I have a Custom JList mode declared as such:

public class CustomListModel<String> extends javax.swing.DefaultListModel<String>

In the same package with no errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:10:27+00:00Added an answer on June 10, 2026 at 9:10 am

    On this line you have declared a type parameter called String:

    public class CustomComboBoxModel<String> extends AbstractListModel<String> {
                                     ^^^^^^
    

    When you later refer to String the compiler thinks you mean the type parameter, not the java.lang.String class.

    The solution here is to remove the type parameter, since you do not need a type parameter.


    The following simplified example gives a similar error message:

    class Foo<String>
    {
        String s = ""; // error: incompatible types
    }
    

    The full error message is:

    Main.java:3: incompatible types
    found   : java.lang.String
    required: String
        String s = "";
                   ^
    

    See it online: ideone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a odd problem with Google Maps APIv2 markers. I'm making a site
I have odd problem: After starting server I got this error: undefined local variable
I have an odd XML document that I have to query. Its from the
I have an odd problem with Django. I have a set of objects that
I have an odd situation in which I need to modify the position of
I have an odd problem where Hibernate is running more queries than I've asked
I have an odd problem. When I click my button to redirect to a
Have an odd problem with a 'Signature Pad I'm building for an employment application...
I am having an odd problem with jQuery 1.5.2 in Chrome. I have code
I have an odd problem that is crashing my app, that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.