Results 1 to 7 of 7
  1. #1
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Err: 'void' type not allowed here

    The code is to call the created method morphStage in order to morph one picture to another as well as display the intermediate pictures (the stages of the morphing process). I need to be able to do this for both a 5 picture sequence and an 11 picture sequence and am completely lost after hours of work only to get my error trouble.
    Here is the code (errors occur in lines 33 & 38 where I am trying to make & display the intermediate pictures):
    Java Code:
    public class TestMorphing
    {
      public static void main(String[] args)
      {
        //*****Test One : Make and display a morph of a five picture sequence*****//
        
        //Choose swan.jpg from mediasources
        String start = FileChooser.pickAFile();
        Picture startingPicture = new Picture(start);
        int startWidth = startingPicture.getWidth();
        int startHeight = startingPicture.getHeight();
       
        //Choose twoSwans.jpg from mediasources
        String end = FileChooser.pickAFile();
        Picture endingPicture = new Picture(end);
        int endWidth = endingPicture.getWidth();
        int endHeight = endingPicture.getHeight();
       
        if(startWidth != endWidth || startHeight != endHeight)
        {
          SimpleOutput.showInformation("Sorry. Your files are not of the same size.");
        }
        else
        {
          int rate = SimpleInput.getIntNumber("Enter Integer Number: ");
          
        Picture[] pictureArray;
        pictureArray = new Picture[rate + 2];
        pictureArray[0] = startingPicture;
        pictureArray[pictureArray.length - 1] = endingPicture;
        
        //Making frame p1 and displaying it
        Picture p1 = new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1));
        pictureArray[1] = p1;
        pictureArray[1].show();
        
        //Making frame p2 and displaying it
        Picture p2 = new Picture(startingPicture.morphStage(startingPicture,endingPicture, 5, 2));
        pictureArray[2] =  p2;
        pictureArray[2].show();
        
        }
      }
    }
    Here is the error:

    2 errors found:
    File: C:\Users\Shawnee\TestMorphing.java [line: 33]
    Error: C:\Users\Shawnee\TestMorphing.java:33: 'void' type not allowed here
    File: C:\Users\Shawnee\TestMorphing.java [line: 38]
    Error: C:\Users\Shawnee\TestMorphing.java:38: 'void' type not allowed here


    Note: I am using DrJava (school requirement... what can you do...)
    Last edited by pbrockway2; 03-08-2012 at 05:27 AM. Reason: code tags added

  2. #2
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Err: 'void' type not allowed here

    Hi AndreaRenee, welcome to the forums! When you post code use the "code" tags: put [code] at the start of your code and [/code] at the end. That way the code will be readable when it appears here.

  3. #3
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Err: 'void' type not allowed here

    I don't know anything about this Picture class, but it looks very much as if its morphStage() method is void (ie does not return anything). In that case it cannot be used as an argument to anything, as in

    Java Code:
    new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))

  4. #4
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Re: Err: 'void' type not allowed here

    Sorry about the code tags... I didn't know.
    Also, this is this morphStage() method I made in my Picture class... If it helps.

    Java Code:
    public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k){
        Picture result = new Picture(startPicture.getWidth(), startPicture.getHeight());
      {
        Pixel[] pixelArrayStart = startPicture.getPixels();
        Pixel[] pixelArrayEnd = endPicture.getPixels();
        Pixel[][][] pixelRGB = null;
        Pixel pixelObjStart = null;
        Pixel pixelObjEnd = null;
        Pixel pixelObjNew = null;
        
        //Colour Values for Start Photo
        int redValueStart = 0;
        int greenValueStart = 0;
        int blueValueStart = 0;
        
        //Colour Values for End Photo
        int redValueEnd = 0;
        int blueValueEnd = 0;
        int greenValueEnd = 0;
        
        //Colour Values for Intermediate Photo
        int redValue = 0;
        int greenValue = 0;
        int blueValue = 0;
        
        //////////////////////////
        
        //Loop through columns
        for (int y = 0; y < getHeight();)
        {
          //Loop through rows
          for (int x = 0; x < getWidth();)
          {
            //Get the pixel and the colour of the pixel
            pixelObjStart = this.getPixel(x,y);
            redValueStart = pixelObjStart.getRed();
            greenValueStart = pixelObjStart.getGreen();
            blueValueStart = pixelObjStart.getBlue();
            pixelObjEnd = this.getPixel(x,y);
            redValueEnd = pixelObjEnd.getRed();
            greenValueEnd = pixelObjEnd.getGreen();
            blueValueEnd = pixelObjEnd.getBlue();
            
            //Morphing loop
            for (int i = 0; i< pixelArrayStart.length;)
            {
              pixelObjStart = pixelArrayStart[i];
              redValue = redValueStart + ((redValueEnd - redValueStart)/(numStages + 1))*k;
              greenValue = greenValueStart + ((greenValueEnd - greenValueStart)/(numStages + 1))*k;
              blueValue = blueValueStart + ((blueValueEnd - blueValueStart)/(numStages + 1))*k;
              
              pixelObjNew.setRed(redValue);
              pixelObjNew.setGreen(greenValue);
              pixelObjNew.setBlue(blueValue);
              
              x++;
              y++;
              i++;
            }
          }
        }
      }
      }

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Err: 'void' type not allowed here

    Which, as pbrockway has already said, does not return anything ('void').
    You cannot pass 'void' as a parameter to a method, or assign it to a variable...which is what you are trying to do with:
    Java Code:
    new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    AndreaRenee is offline Member
    Join Date
    Mar 2012
    Posts
    9
    Rep Power
    0

    Default Re: Err: 'void' type not allowed here

    Ah well, this is what I get for being dumber than a post and apparently not knowing how to read too. Thanks for the help

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Err: 'void' type not allowed here

    We all suffer from code blindness at times.
    Goes with the territory.
    :)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. void type not allowed here
    By Nazneen Ali in forum New To Java
    Replies: 1
    Last Post: 07-24-2011, 02:23 PM
  2. Replies: 8
    Last Post: 05-25-2011, 07:26 PM
  3. void type not allowed
    By jockhip12 in forum New To Java
    Replies: 6
    Last Post: 05-05-2011, 06:26 PM
  4. 'void' type not allowed here
    By Torgero in forum New To Java
    Replies: 15
    Last Post: 10-05-2008, 12:08 AM
  5. is void a type?
    By mary in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 09:12 PM

Tags for this Thread

Posting Permissions

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