File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Attempting to create array for Color Class - invalid integer inputs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Attempting to create array for Color Class - invalid integer inputs" Watch "Attempting to create array for Color Class - invalid integer inputs" New topic
Author

Attempting to create array for Color Class - invalid integer inputs

Shawn Grasso
Greenhorn

Joined: Feb 27, 2013
Posts: 2
I'm trying to define a color by inputting multiple Red, Green, and Blue values from three arrays - although I can't seem to do so. I understand that this type of code may not be possible in the manner that i've written it... how can i accomplish this?

Here's the code:



I'm new to Java so any help would be much appreciate - thanks!
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Look at line 14 and describe to us in plain language what you think it does. When you do, it would help if you would address each of these questions:

  • How many Color object instances does Line 14 create?
  • Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")?
  • Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)?
  • What error message do you get when you try to compile this (or from your IDE), and what do you think it means?
  • Shawn Grasso
    Greenhorn

    Joined: Feb 27, 2013
    Posts: 2
    Look at line 13*? and describe to us in plain language what you think it does. When you do, it would help if you would address each of these questions:

    How many Color object instances does Line 13 create? 3
    Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")? I mean to put multiple R,G,B values under one color in order to combine those values from each of the above arrays. Listing each color combination out wouldn't be a sound way of doing so.
    Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)? Thank-you, skipped over 3.
    What error message do you get when you try to compile this (or from your IDE), and what do you think it means? No suitable Constructor found.



    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38349
        
      23
    Using parallel arrays is a very dubious practice; it is very error‑prone because the arrays might get out of phase with each other.
    Have you read through the documentation about constructors for that class? You cannot pass an array.
    You mentioned creating an array for Color, but you haven’t created any such array.
    Stevens Miller
    Ranch Hand

    Joined: Jul 26, 2012
    Posts: 523
        
        3

    Shawn Grasso wrote:How many Color object instances does Line 14 create? 3

    A constructor returns a reference to one object: the one it just constructed. You may need to study up on the basics of the new keyword and constructors before going further.

    Why do you assign the result to a variable named "acolor" (instead of, for example, "manycolors")? I mean to put multiple R,G,B values under one color in order to combine those values from each of the above arrays. Listing each color combination out wouldn't be a sound way of doing so.

    If you are trying to mix those colors into a single color, then you need to do that before creating the one Color object that will hold their combined value. Or, you will need to create as many Color objects as you have colors in your arrays (and, btw, I agree with Campbell that parallel arrays are dangerous, as you've already experienced), then combine them into a single Color object. (I think that's not what you're trying to do, however.)

    Why are there ten values in each of your redvaluesColor and greenvaluesColor arrays (and only seven values in your bluevaluesColor array)? Thank-you, skipped over 3.

    No problem. See Campbell's comment, though.

    What error message do you get when you try to compile this (or from your IDE), and what do you think it means? No suitable Constructor found.

    And that's what your problem is. You are passing arrays to the Color constructor. There is no Color constructor that accepts arrays.

    Now, you did answer my suggested questions, but you haven't yet described what it is you are trying to do. Do that, and maybe we can help.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Attempting to create array for Color Class - invalid integer inputs