Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java public int[]GetArray()表示表达式的开头非法_Java_Image Processing - Fatal编程技术网

Java public int[]GetArray()表示表达式的开头非法

Java public int[]GetArray()表示表达式的开头非法,java,image-processing,Java,Image Processing,我试图用Java创建一个2D图像数组 以下是我目前掌握的情况: public int[][] GetArray() { //NetBeans is saying 'Illegal Start of Expression' on this line getimage data; getwidth; getheight; int[][] array = new int[width][height]; for (loo

我试图用Java创建一个2D图像数组

以下是我目前掌握的情况:

   public int[][] GetArray() {  //NetBeans is saying 'Illegal Start of Expression' on this line

        getimage data;
        getwidth;
        getheight;
        int[][] array = new int[width][height];

    for (loop through width) {
        for (loop through height) {
            array[q][p] = raster.getSample(p, q, 0);
        }
    }

    return array;
我尝试将返回部件设置为:-

    return array[][];
但这产生了一个错误,说找不到符号


我对Java比较陌生,我真的很想尽快变得更好,如果您能帮助我,我将非常感激。

如果您想返回数组,请这样做

    return array;    // CORRECT
public class MyClass
{ 

    // main is a method just like GetArray, defined inside class

    public static void main(String[] args)
    {
          // do something
    }

    // other methods are defined outside main but inside the class.

    public int[][] GetArray() {

            int width = 5;   // change these to your dimensions
            int height = 5;

            int[][] array = new int[width][height]; 

            int q,p;

            for(q=0;q<width;q++)
            {
                 for(p=0;p<height;p++)
                 {
                     array[q][p] = raster.getSample(p, q, 0);
                 }
            }

        return array;
    }   
}
你所做的是不正确的

    return array[][];    // INCORRECT
您的函数应该如下所示

    return array;    // CORRECT
public class MyClass
{ 

    // main is a method just like GetArray, defined inside class

    public static void main(String[] args)
    {
          // do something
    }

    // other methods are defined outside main but inside the class.

    public int[][] GetArray() {

            int width = 5;   // change these to your dimensions
            int height = 5;

            int[][] array = new int[width][height]; 

            int q,p;

            for(q=0;q<width;q++)
            {
                 for(p=0;p<height;p++)
                 {
                     array[q][p] = raster.getSample(p, q, 0);
                 }
            }

        return array;
    }   
}
返回数组时,不应使用

返回数组[]

不应使用方括号[]。在return语句中,我们不应该提及数组的维度

改用


返回数组;这是发布实际代码的正确方式

麻烦吗?表达式的非法开始在哪里?数组是如何定义的?我不想发布代码,因为这是我学位课程的一部分,我不想被抓出来搞plaigarism…@DrYap我在其中定义了它main@BenjaminFranklin然后形成一个相似的代码?