Can't convert int to int[]    URGENT!

HI list!
Here is the code part I have:
/** Holds the permutated groups which are arrays of integers. */
Vector v;
if(arg.length<3) System.exit (0); //Need at least 3 arguments
elements=new int[arg.length-1]; //Create array to hold elements
/* Copy the arguments into the element array. */
for(i=0;i<arg.length-1;i++) elements=Integer.parseInt(arg[i+1]);
groupsize=Integer.parseInt(arg[0]); //Get the number in each group.
calc(groupsize,elements.length); //Find out how many permutations there are.
v=permutate(groupsize,elements); //Do the permutation
for(i=0;i<v.size();i++) { //Print out the result
elements=(int[]) v.get(i);
System.out.println("");
for(j=0;j<elements.length;j++) System.out.print(elements
[j]+" ");
System.out.println("\nTotal permutations = "+v.size());
and the error I get is:
Permutate.java:26: Incompatible type for =. Can't convert int to int[]. for(i=0;i<arg.length-1;i++) elements=Integer.parseInt(arg[i+1]);

elements=(int[]) v.get(i);
The above statement is illegal. Its not possible to
use an array type in casting at all.
Basically you are trying to do a kind of multiple
casting, which is not possible.
You might want to store vectors in vector v instead of
arrays in vector v. Its better to do this.There's nothing wrong with the line
elements = (int[]) v.get(i);
assuming the returned object from the vector is in fact an array of int. Even then, it is a runtime exception condition not a compile-time error.
Using arrays is perfectly valid where you know the size of the array at creation and do not need to resize it during use... The arrays are fast and compact. This is however not a comment on the approach taken in this case but merely an observation that arrays are not always an inferior choice to one of the collection classes.
Now put up your dukes... ;)

Similar Messages

  • How to convert varchar to int in MSSQL?

    Hi,
    I am using mssql. how can i convert varchar to int type.
    for eg.
    id (int) txt(varchar)
    1 ---------10
    2 ---------10a
    3 ---------10b
    i want to convert varchar to int. HOw? pls explain with query.
    Thanks
    edward

    "10a" wouldn't normally be considered a number. So what sort of number do you expect it to be?
    Other than that you can look at the substring and convert/cast functions.

  • How to convert String to int in JSP?

    Hi,
    I set a session attribute in Servlet and want use it in JSP, How can I convert it to int or Integer?
    the line in my code doesn't work:
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    Thanks in advance.
    Wolf
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    <HTML>
    <HEAD>
    <TITLE>Using the for Statement</TITLE>
    </HEAD>
    <BODY>
    <H1>Using the for Statement</H1>
    <%=session.getAttribute("vehiclequantity") %>;
    <%
    int loopIndex;
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    out.println(quantity);
    for (loopIndex = 1; loopIndex <=2; loopIndex++) {
    out.println("This is iteration number "
    + loopIndex + "<BR>");
    %>
    </BODY>
    </HTML>

    Learning how to read errors and understand them will help you solve your problems quicker by yourself... So lets take a look at the error and classes involved...
    The error says:
    "Cannor Resolve Symbol: method valueOf(java.lang.Object) in the class java.lang.Integer" and gives you line line where the error occurs: Integer quantity = Integer.valueOf(session.getAttribute("vehiclequantity"));
    Now, if we look at the API for the Integer we notice that are are only two valueOf methods: valueOf(java.lang.String s) and valueOf(java.lang.String s, int radix). Not valueOf(java.lang.Object) method.
    Now we look at the getAttribute(java.lang.String name) method of HttpSession we see that the method returns a java.lang.Object. Now, you know you put a java.lang.String into that attribute, but the get method returns an Object. This is because you could have put any object in there, an Integer, a String, or some other class instance. But you know it is a String, so you can cast the returned value to a String, so that you will be calling the valueOf(java.lang.String s) method of Integer with the Object returned from the HtttpSession's getAttribute(java.lang.String name) method:
    Integer quantity = Integer.valueOf((String)session.getAttribute("vehiclequantity"));

  • How can I convert an int to a string?

    Hi
    How can I convert an int to a string?
    /ad87geao

    Here is some the code:
    public class GUI
        extends Applet {
      public GUI() { 
        lastValue = 5;
        String temp = Integer.toString(lastValue);
        System.out.println(temp);
        showText(temp);
      private void showText(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            tArea2.setText(text + "\n");
    }

  • How can I convert a String into an int?

    I need to use command-line args. So I enter "java Main 123" and I want to use 123 not as a String but as an int.
    How can I convert it into an int?
    Thank You!!
    Sprocket

    Example method (you don't need to use a method unless you do this a lot)
    private int stringTOInt (String aString)
    int result = 0;
    try
    result = Integer.parseString(aString);
    catch (Exception ex)
    System.out.println ("Failed to convert string " + aString + " to int.");
    return result;
    }

  • Can't convert int to java.lang.Integer.

    Hi everyone.
    I'm working on an auction site at the moment and have problems gaining a bidID number. This is part of my code and my error.
    AuctionFacade aHse = (AuctionFacade) application.getAttribute("AuctionFacade");
    String strTraderName = (String)session.getAttribute("traderName");
    String strPassword = (String)session.getAttribute("password");
    String strIDNum = request.getParameter("auctionID");
    Integer intID = Integer.valueOf(strIDNum);
    Integer [] bids = aHse.getAllBids(intID);
    float fltYourBid = aHse.getBidPrice(bids.length);
    ^
    Can't convert int to java.lang.Integer.
    can anyone help please?

    So, does "aHse.getBidPrice" expect an int or an Integer as its parameter? And does it return an int, or an Integer, or what? The answer to those questions may lead to your solution -- look at what you are actually using as the parameter, for example.

  • Can't convert int to java.lang.Object

    When I deploy my customer Bean, the following error occures, I think the main problem is Can't convert int to java.lang.Object, does anyone facing the same problem with me?
    <pre>C:\j2sdkee1.3\repository\home\gnrtrTMP\CustomerApp\CustomerBean_RemoteHomeImpl.j
    ava:27: Incompatible type for declaration. Can't convert int to java.lang.Object
    java.lang.Object primaryKey = ejb.ejbCreate(param0, param1, para
    m2);
    ^
    C:\j2sdkee1.3\repository\home\gnrtrTMP\CustomerApp\CustomerBean_RemoteHomeImpl.j
    ava:57: Incompatible type for =. Can't convert int to java.lang.Object.
    primaryKeys = ejb.ejbFindByPrimaryKey( param0);
    ^</pre>
    I really need your help!!!

    you can only convert one object type to another. Integer is an object int isnt. You might want to convert int to Integer and then go ahead.
    see if it works.

  • Error message:can't convert int to int[]

    Hi,
    I am trying to build a java code which convert decimal to binary
    but ,I found error message "can not convert int to int[]"
    some line of code:
    int i=12,n=0;
    int arr[n]=i%2;
    n++;
    here I am trying to store remainder in an integer arrary.
    how can i do this???????
    guide me please
    -shobhit singh

    shobhit_onprob wrote:
    i want to store some integer values in to an integer arraryDid you follow the address that was given to you? I doubt it, and even if you did, 2 minutes is not enough time to read, let alone understand, the tutorial.
    Go back there, it describes all the basics you need.

  • Converting from unsigned int / short to byte[]

    Can anybody help me, I am trying to convert from:
    - unsigned int to byte[]
    - unsigned short to byte[]
    I will appreciate your help lots. thanks.

    @Op.
    This code converts an integer to a byte[], but you have to consider the byte order:
            int value = 0x12345678;
            byte[] result = new byte[4];
            for (int i=3; i>=0; i--) {
                result[i] = (byte)(value & 0xff);
                value = value >> 8;
            }This is another option:
            int dummy = 7;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            os.write(dummy);
            byte[] bytes = os.toByteArray();Kaj

  • Convert Double to Int

    Hi,
    How can I convert a double datatype eg. 0.309414484580145 to an integer?
    I want to round the double to the the nearest integer. Maybe there is another way?
    Regards
    Pierre

        public Integer doubleToInteger(Double theDouble) {
             /* the part before the decimal */
             Integer whole = Integer.valueOf(theDouble.toString().substring(0, theDouble.toString().indexOf(".")));
             int part2 = -1;
             int part3 = -1;
             String theString = theDouble.toString();
             int length = theString.substring(theString.indexOf(".")+1).length();
             /* the parts after the decimal */
             int part1 =
              Integer.valueOf(theDouble.toString().substring(
                        theDouble.toString().indexOf(".")+1, theDouble.toString().indexOf(".")+2));
             if(length > 2) {
              part2 =
              Integer.valueOf(theDouble.toString().substring(
                        theDouble.toString().indexOf(".")+2, theDouble.toString().indexOf(".")+3));
             if(length > 3) {
             part3 =
              Integer.valueOf(theDouble.toString().substring(
                        theDouble.toString().indexOf(".")+3, theDouble.toString().indexOf(".")+4));
             /* do some rounding */
             if(part3 >= 5){
              part2++;
              if(part2 == 0) {
                  part1++;
             if(part2 >= 5) {
              part1++;
              if(part1 == 0) {
                  whole++;
             if(part1 >= 5) {
              whole++;
             return whole;     
        }So how unnecessary was this exactly?

  • How to solve this Error?? Error_2_Cannot implicitly convert type 'int' to 'int[]'_

    Hi,
    I created a structure. It contains 1& 2 diamensional arrays. Now I want to pass values to these arrays. But at that time I got the following error.
        Error 2 Cannot implicitly convert type 'int' to 'int[]' 
            publicstructtest
              [FieldOffset(160)]
             [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 3)]
            publicint[]
    DC;
               [FieldOffset(168)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
              publicfloat[]
    IN;
               [FieldOffset(176)]
              [MarshalAs(UnmanagedType.ByValArray,
    SizeConst = 8)]
            publicbyte[,]
    us;
    privatevoidbutton1_Click(objectsender,
    EventArgse)
    //int[] T_ADC = new int[3];
                array[0].DC =12
                array[0].IN[0] = 11;
                array[0].us[0, 0] = 1;

    @DAANNIII
    >>I wrote the code as follows
    array[0].DC[0]
    =12
    but after that I got an error that  " Object reference not set to an instance of an object".Why this type of error occurs??
    Still confused about how you define variable "array[0]".
    Based on your error information, because your DC is null. As I said before, DC is an int[]. You must assign an array to DC.
    int[] array = new int[] { 2, 43 };
    test s = new test();
    s.DC = array;
    s.DC[0] = 12;//It works fine
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Help trying to convert string to int

    Hey im trying to input a string in an applet then turn it into a integer so i can use it any ideas?

    long val = Long.parseLong(string);
    if(val > Integer.MAX_VALUE || val <
    Integer.MIN_VALUE) {
    throw new Error("I don't like you :p");
    int intVal = (int) val;No real need to use parseLong and check explicitly the limits. The check for MIN and MAX is performed implicitely inside Integer.parseInt(string, 10), which is called by both new Integer(string).intValue() and Integer.parseInt(string) . When the check fails, it throws a NumberFormatException.
    The only difference between post#1 and post#2 is that the latter it stores the int value in the internal int data member after the call to Integer.parseInt(string, 10), hence the intValue() subsequent call.

  • How can I make byte[] to int?(the byte order is diff for intel and sparc))

    i do a net program with java, it send message
    from sun to pc with socket, i want to change
    byte[] to int and int to byte[], the byte order is
    diff from sparc and intel, and i can not use
    the ByteArrayStream, is there any way?
    thanks.

    you can connect the headset to something like this
    http://www.ebay.com/itm/NEW-MaelineA-3-5mm-Female-to-2-Male-Gold-Plated-Headphon e-Mic-Audio-Y-Splitter-/381100440348
    and then connect the mic to the input and the headset to the headset port

  • Converting chars to ints, get a strange math error...

    Here's the code I have.
    import java.util.*;
    public class Encryption {
         public static void main(String[] args) {
              Scanner sc1 = new Scanner(System.in);
              System.out.print("Enter a four-digit integer to be encrypted: ");
              String encrypt = sc1.nextLine();
              char a = encrypt.charAt(0);
              char b = encrypt.charAt(1);
              char c = encrypt.charAt(2);
              char d = encrypt.charAt(3);
              int as = new Integer(a).intValue();
              int bs = new Integer(b).intValue();
              int cs = new Integer(c).intValue();
              int ds = new Integer(d).intValue();
              int codea = (as + 7);
              while (codea > 9) {codea = codea - 10;}
              int codeb = (bs + 7);
              while (codeb > 9) {codeb = codeb - 10;}
              int codec = (cs + 7);
              while (codec > 9) {codec = codec - 10;}
              int coded = (ds + 7);
              while (coded > 9) {coded = coded - 10;}
              int finala = codec;
              int finalb = coded;
              int finalc = codea;
              int finald = codeb;
              String encrypted = ("" + finala + "" + finalb + "" + finalc + "" + finald + "");
              //System.out.println ("The encrypted number is " + encrypted + ""); set aside while debugging
              System.out.println(" " + a + " " + b + " " + c + " " + d + " ");
              System.out.println(" " + as + " " + bs + " " + cs + " " + ds + " ");
    }Now here's the console.
    Enter a four-digit integer to be encrypted: 1234
    1 2 3 4
    49 50 51 52
    When I went from char to int, 1 became 49, 2 became 50, etc...how did this happen?

    class Fubar1
        public static void main(String[] args)
            System.out.println("'1' = " + '1'); // prints the char
            System.out.println("(int)'1' = " + (int)'1'); // prints the ASCII (unicode?) number that represents that char
    }

  • Converting char to int - Easy surely?!

    A very easy question I know but it's drving me round the bend!!!
    I have searched the forums but the answers I have seen don't seem to work?!
    Basically I have a section of code like this:
    String argument = "-0";
    int member = (int)argument.charAt(1);
    member then gets populated with 48 and not 0. Why??!
    Any help would of course be greatly appreciated.

    48 is the internal representation of the character '0'. This is not only true for the Unicode used by Java but also for the ANSI and ASCII codes. The character coded as 0 is often used as string terminator, e.g. for the standard C strings.
    So if you want to retrieve the value of a digit character, you need to subtract 48. But make sure it is a digit, i.e. a character code between 48 and 57, both inclusive. You might also want to check out the method Integer.parseInt(String).

Maybe you are looking for

  • Can't connect Macbook Air 10.8.5 to new Officejet 6700

    I don't have a CD drive, so I'm trying to set-up via instructions from the internet. Thus, far, I've uninstalled the previous HP printer, downloaded the suggested download multiple times--with no luck. There is no connection between my computer and t

  • Can i upgrade my macbook pro to 10.6

    I have the original MacBook Pro with Intel 2.16 GHz Core Duo processor, and 2 GB RAM. I am currently running 10.5.8, but I have an iPhone 5 running the latest iOS. In order to get the latest iTunes on my computer so that I can sync my iPhone, I need

  • Issue with encoding while reading email msg from pst

    I have a pst and I have issue with few messages which has russian characters in it, when i open the email it shows garbage values. But when i go to OtherActions->Encoding from the email menu option I see that the Encoding was set to "Cyrillic (KOI8-R

  • I have set up iCloud for my iPhone, iPod, and macbook but photos and music are not downloading...

    I have set up iCloud for my iPhone, iPod, and macbook but photos and music are not downloading... ICloud preferences have been checked, photo stream enabled on iphone-- what's missing?

  • Template vs SSI vs library

    Hi: In order to make global changes to a nav menu (for example), I know that: * You can make changes to the linked pages from a template, if employed, and then upload the updated pages... * You can use a server-side include which updates pages with a