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 6789843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:39:13+00:00 2026-05-26T17:39:13+00:00

I cant get rid of one new typesafety warning in java7. I have the

  • 0

I cant get rid of one new typesafety warning in java7.

I have the following JCombobox object defined

private JComboBox<Integer> combobox_current_year;

And the the constructor

combobox_current_year = new JComboBox(options.getList_years().toArray());

Java 7 gives me now the following warning:

Type safety: The expression of type JComboBox needs unchecked
conversion to conform to JComboBox

After changing the code to

combobox_current_year = new JComboBox<Integer>((Integer[]) options.getList_years().toArray());

I get the following exception:

Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: [Ljava.lang.Object;
cannot be cast to [Ljava.lang.Integer; at
jamm.gui.FinanzmanagerGui.mainWindow(FinanzmanagerGui.java:123) at
jamm.StartJamm$1.run(StartJamm.java:43) at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) at
java.awt.EventQueue.access$000(EventQueue.java:101) at
java.awt.EventQueue$3.run(EventQueue.java:666) at
java.awt.EventQueue$3.run(EventQueue.java:664) at
java.security.AccessController.doPrivileged(Native Method) at
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

  • 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-05-26T17:39:14+00:00Added an answer on May 26, 2026 at 5:39 pm

    The problem is that the toArray() method returns an object of type Object[] which is a totally different type to Integer[] (so making the cast fail). You have to pass in a differently-typed array to toArray(…) to resolve that. The most efficient method of getting an array out of a list is this:

    List<Integer> tmp = options.getList_years();
    combobox_current_year = new JComboBox<Integer>(
            tmp.toArray(new Integer[tmp.size()]));
    

    I use a temporary variable to hold the list because I want to pre-size the array so that the values can be just copied into it. Passing in a shorter array (e.g., of length 0) would also work, but would cause an extra allocation to happen. (You could make it work by keeping the length-zero array in a private static field; it’s effectively immutable so you can share it with no ill-consequences. But I prefer to pre-size as that leaves less clutter at the class level.)

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

Sidebar

Related Questions

I am generating assembly on runtime . Problem is that i cant get rid-of
I have read other related question but i cant really get them to relate
Cant seem to get the following to find the 'skull' button when the 'heart'
I have one javasctipc class... Lets call it X. myClass = new X(bunc, of,
I cant get a PHP file to send correct headers at my WAMP server.
I'm probably doing something realy stupid but I cant get this to work: var
with $element->children() i cant get all the child elements of current element. but how
Im trying to plot the roots of a polynomial, and i just cant get
I cant quite get my head around what the ^ is doing in my
I cant seem to get VB to focus on a textbox correctly at the

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.