Results 1 to 5 of 5
  1. #1
    OPTYMISTA is offline Member
    Join Date
    Feb 2013
    Posts
    18
    Rep Power
    0

    Default Problem converting int[] to String[]

    Java Code:
    public static void main(String[] args) {
    		 int[] aar = {2010,2011,2012,2013,2014,2015,2016};
    		 String[] manedStrings = { "Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"};
    		 int[] dag31 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
    		 
    		 JFrame ramme = new JFrame("Calendar");
    		 JComboBox<String> year,month,day;
    		 
    		 // HERE ACCUR ERROR in year and day
    		 year = new JComboBox(Arrays.toString(aar));
    		 month = new JComboBox<String>(manedStrings);
    		 day = new JComboBox(Arrays.toString(dag31));
    		 
    		 String valg = String.valueOf(year.getSelectedItem());
    		 String valg2 = String.valueOf(month.getSelectedItem());
    		 String valg3 = String.valueOf(day.getSelectedItem());
    		 
    		    Calendar cal1 = new GregorianCalendar(Integer.valueOf(valg),Integer.valueOf(valg2) ,Integer.valueOf(valg3));
    		    cal1.set(Calendar.MONTH, Calendar.MAY);
    
    		    System.out.println("Year: " + cal1.get(Calendar.YEAR));
    		    System.out.println("Month: " + (cal1.get(Calendar.MONTH) + 1));
    		    System.out.println("Days: " + cal1.get(Calendar.DAY_OF_MONTH));
    
    		    // Format the output with leading zeros for days and month
    		    SimpleDateFormat date_format = new SimpleDateFormat("yyyy/MM/dd");
    		    System.out.println(date_format.format(cal1.getTime()));
    
    		  }
    Have You some ideas round why I get error message in this code?

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,937
    Rep Power
    19

    Default Re: Problem converting int[] to String[]

    What line are you getting the error message on?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,937
    Rep Power
    19

    Default Re: Problem converting int[] to String[]

    Also please post the full error message, including a stack trace if it is a runtime error.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    OPTYMISTA is offline Member
    Join Date
    Feb 2013
    Posts
    18
    Rep Power
    0

    Default Re: Problem converting int[] to String[]

    Also You can't call
    Java Code:
    JComboBox(Arrays.toString(aar));
    , because it's a simple string. It should be String array.
    Java Code:
    The constructor JComboBox(String) is undefined
    . Any ideas how to convert int[] to String[]?

    @EDIT

    I edited my arrays to Strings types:
    Java Code:
    String[] aar = {"2010","2011","2012","2013","2014","2015","2016"};
    		String[] manedStrings = { "Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"};
    		String[] dag31 = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
    Then I can add they here:
    Java Code:
    year = new JComboBox(aar);
    		year.setEditable(true);
    		year.setSelectedIndex(0);
    		month = new JComboBox<String>(manedStrings);
    		month.setEditable(true);
    		month.setSelectedIndex(0);
    		day = new JComboBox(dag31);
    		day.setEditable(true);
    		day.setSelectedIndex(0);
    String valg = String.valueOf(year.getSelectedItem());
    		String valg2 = String.valueOf(month.getSelectedItem());
    		String valg3 = String.valueOf(day.getSelectedItem());
    		
    		System.out.print(valg);
    But I get an error message in this line:
    Java Code:
    cal1 = new GregorianCalendar(Integer.parseInt(valg),Integer.parseInt(valg2) ,Integer.parseInt(valg3));
    ERROR:
    Java Code:
    2010Exception in thread "main" java.lang.NumberFormatException: For input string: "Januar"
    	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    	at java.lang.Integer.parseInt(Integer.java:492)
    	at java.lang.Integer.parseInt(Integer.java:527)
    	at design.Kalendarz.<init>(Kalendarz.java:61)
    	at design.Kalendarz.main(Kalendarz.java:84)
    Last edited by OPTYMISTA; 04-03-2013 at 12:34 AM.

  5. #5
    OPTYMISTA is offline Member
    Join Date
    Feb 2013
    Posts
    18
    Rep Power
    0

    Default Re: Problem converting int[] to String[]

    I solved problem! ;)

Similar Threads

  1. Replies: 1
    Last Post: 02-09-2013, 02:45 PM
  2. Converting int to string or??
    By Redexe in forum New To Java
    Replies: 4
    Last Post: 04-06-2012, 12:47 AM
  3. A problem with converting String to Int.
    By hell00 in forum New To Java
    Replies: 3
    Last Post: 12-19-2011, 11:15 PM
  4. Converting to String
    By darek9576 in forum New To Java
    Replies: 1
    Last Post: 03-13-2010, 10:07 PM
  5. Is it OK to do this... (converting int to string)
    By Psyclone in forum New To Java
    Replies: 1
    Last Post: 02-16-2010, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •