Results 1 to 17 of 17
  1. #1
    effa is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default incompatible types

    incompatible types
    found : void
    required: int
    result[j][i]=seq.shift1();

    i'm trying to solve this error but i couldn't. could anyone help me to solve this error..

    ur help is much appreciated.....

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    And also post what you've done, part of your code which is relevant. It's easy for us to comment on you.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by effa View Post
    incompatible types
    found : void
    required: int
    result[j][i]=seq.shift1();

    i'm trying to solve this error but i couldn't. could anyone help me to solve this error..

    ur help is much appreciated.....
    My bet: result is a two dimensional array of ints and method shift() returns a void (i.e. nothing). The compiler saw that and didn't like it; method shift() should return an int.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    effa is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    
    public class try1 {
    	int N;
    	    protected int n = (int) (Math.log(N) / Math.log(2));
    	    int[][] mix;
        protected int[] out;
    
    
    
    	public void setInout() {
    	        out = makeRandom(N);
    
    	    }
    
    		private int[] makeRandom(int rowSize) {
    	        int i;
    	        int[] outMatrix = new int[rowSize];
    	        int[] shuffleMatrix = new int[rowSize];
    	        shuffleMatrix = shuffly.shuffler(rowSize);
    	        for (i = 0; i <= rowSize - 1; i++) {
    	            outMatrix[i] = shuffleMatrix[i];
    
    	        }
    	        return outMatrix;
    	    }
    
    
    public int shift1() {
    	        int i, temp;
    
    	        int shright = n;
    	        int shleft = (int) (Math.pow(2, n - 1) - 1) << n;
    	        int j = 0;
    
    	        for (i = 0; i <= n - 1; i++) {
    	            for (j = 0; j <= N - 1; j++) {
    	                temp = j * N + out[j];
    	                mix[j][i] = temp & shleft;
    	                mix[j][i] = mix[j][i] >> shright;
    	            }
    	            shleft /= 2;
    	            shright--;
    	        }
    	       //int result[j][i] = mix[j][i];
    	       return mix[j][i];
        }
    
    
    
    public static int main(String[] args){
    
    
    		System.out.print("Enter Matrix Size : ");
    		Scanner scan = new Scanner(System.in);
    		int N = scan.nextInt();
    
            int i, j;
    
    
            SeqDecSim seq = new SeqDecSim(N);
    
    
     seq.setInout();
    
    
    
    
    	int result[j][i]=seq.shift1();
    
    
    			for (i = 0; i <= 3; i++) {
    	         for (j = 0; j <= 8; j++) {
    
                System.out.println(result[j][i]);
    }
    
    }
    }
    }
    hi..
    when i run this pgram..
    the error is:

    incompatible types
    found : void
    required: int[][]
    int result[][]=seq.shift1();
    Last edited by Eranga; 02-03-2011 at 02:22 AM. Reason: code tags added

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    The shift1 method returns a single int but you are trying to assign it to a 2D array. Does not compute. Perhaps you want the method to return a 2D array instead. Or perhaps assign the returned int to a single position in the result 2D array.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default

    Please use code tags.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by effa View Post
    when i run this pgram..
    the error is:

    incompatible types
    found : void
    required: int[][]
    int result[][]=seq.shift1();
    I don't believe you got that error diagnostic message because method shift1() returns an int. (but an int[][] return type is required).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    Please use code tags.
    If you don't know how to do that, please check my forum signature.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    I don't believe you got that error diagnostic message because method shift1() returns an int. (but an int[][] return type is required).
    You said that it's not complain about the incompatibility?

    By the time shift1() invoke from SeqDecSim class, which I cannot see in the above code.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default

    Good point.
    The shitf1() given in that code is from a different class (try1) isn't it?

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    You said that it's not complain about the incompatibility?

    By the time shift1() invoke from SeqDecSim class, which I cannot see in the above code.
    Ah, yes, it's another shif1() method; isn't it nice when ops show code that has nothing to do with the problem; it's international "Mislead The Repliers Day" again ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default

    You say that like it's a frustrating annoyance rather than a thing of joy and fun.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    You say that like it's a frustrating annoyance rather than a thing of joy and fun.
    Not an annoyance; it's just the feeling of shame when I have to admit (again) that I fell for the trap. I should keep my mouth shut more ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    I should keep my mouth shut more ;-)

    Oh no! Remember the coffee! Unless you intend resorting to mainlining the stuff...

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by pbrockway2 View Post
    Oh no! Remember the coffee! Unless you intend resorting to mainlining the stuff...
    Hm, coffee ... I'll have another espresso and roll myself another cigaret; thank for the tip! I always drink this coffee, Im hooked to it ;-)

    kind regards,

    Jos (<--- coffee brand spammer ;-)
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    the syntax of the method shift1 is wrong. i think you should read how methods and arrays works in java. hope also my example may help:

    Java Code:
    public class try1 {
    
    	public static int[][] shift1(int n) {
    		int i[][] = new int[10][10];
    		if (n == 0) {
    			System.out.println("return null");
    		 return null;
    		}
    		else {
    			System.out.println("return i[][]");
    			return i;
    		}
    	}
    
    	public static void main(String[] args) {
    		int[][] j;
    		// even if shift1 return null all is ok
    		j = shift1(0);
    		if ( j == null) {
    			System.out.println(" j is null");
    		}
    		// this time shift1 will return an int[][]
    		j = shift1(1);
    		if ( j != null) {
    			System.out.println(" j is not null");
    		}
    	}
    }

Similar Threads

  1. Incompatible types
    By bayan in forum New To Java
    Replies: 5
    Last Post: 11-04-2010, 08:43 AM
  2. incompatible types error
    By magic in forum New To Java
    Replies: 3
    Last Post: 06-02-2010, 04:58 PM
  3. Incompatible operand types int and double[][]
    By Haske2r in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 05:26 PM
  4. Incompatible types
    By coltragon in forum New To Java
    Replies: 5
    Last Post: 01-15-2010, 04:47 PM
  5. Replies: 3
    Last Post: 12-14-2008, 01:52 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
  •