Results 1 to 5 of 5
  1. #1
    prizzly is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Exclamation arrange(java.lang.String[][]) in Test cannot be applied to (java.lang.String) arrange

    Hi, I am not able to pass a 2d array of string.

    error msg shown:
    arrange(java.lang.String[][]) in Test cannot be applied to (java.lang.String) arrange(arr[12][5]);



    import java.lang.*;
    import java.io.*;

    public class Test {

    static int count;
    static String[][] arr=new String[12][5];
    public static void main(String[] args) {
    String[] lines = new String[0];
    String path = "Liar.txt";
    BufferedReader br = null;

    try {
    File file = new File(path);
    br = new BufferedReader(
    new InputStreamReader(
    new FileInputStream(file)));
    String line;

    while( (line = br.readLine()) != null ) {


    print(line);


    }
    br.close();

    } catch(IOException e) {
    System.out.println("read error: " + e.getMessage());
    }
    for(int x=0;x<12;x++){
    for(int y=0;y<5;y++){
    System.out.print(arr[x][y]+" ");
    }
    System.out.print("\n");
    }
    arrange(arr[12][5]);
    }


    private static void print(String data1)
    {

    String data=data1.replaceAll("\\b\\s{2,}\\b", " "); // replace multiple spaces by a single space between words

    String[] words = data.split("\\s"); //words is an array of splitted words in a line(1 space considered as 1 word)


    for(int j = 0; j < words.length; j++)
    { arr[count][j]=words[j];
    // System.out.print(arr[count][j]);
    }//word.length gives no. of words in a line.
    count++;
    }
    private static void arrange(String[][] arr1)
    {
    for (int i=0;i<=count;i++){
    for(int j=0;j<arr1.length;j++){
    if (i==0){
    int n=Integer.parseInt(arr1[i][j]);
    System.out.println("...."+n);
    }

    if (arr1.length==2){
    int m=Integer.parseInt(arr1[i][1]);
    System.out.println(">"+m);


    }

    }
    }

    }
    }


    Input File:

    5
    Stephen 1
    Tommaso
    Tommaso 1
    Galileo
    Isaac 1
    Tommaso
    Galileo 1
    Tommaso
    George 2
    Isaac
    Stephen

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by prizzly View Post
    Hi, I am not able to pass a 2d array of string.

    error msg shown:
    arrange(java.lang.String[][]) in Test cannot be applied to (java.lang.String) arrange(arr[12][5]);
    Read what the compiler is complaining about: it found a method 'arrange' that needs a two dimensional array of Strings as its parameter but you are trying to call it with a single String as a parameter:

    Java Code:
            arrange(arr[12][5]); // <-- here
    Of course that doesn't work; supply a two dimensional array as a parameter, not just one String element.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    prizzly is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Default

    but as I understand I am using arr[12][5] as a 2D string array, in which I had stored data from the file and then passing it to another method arrange(String[][] arr1).
    I am not able to understand , what exactly I am missing?

  4. #4
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    pass in the array
    Java Code:
    arrange(arr);
    because you have defined your function to take in a 2D string array , as in
    Java Code:
    public static void arrange(String[][] arr1)
    if you do this
    Java Code:
    arrange(arr[12][5]);
    you are passing in a string that is contained in row 11 item 6 of arr array, which is wrong.

  5. #5
    prizzly is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 10-10-2010, 01:17 AM
  2. Replies: 4
    Last Post: 01-29-2010, 10:57 PM
  3. Replies: 3
    Last Post: 12-01-2008, 06:40 AM
  4. Replies: 4
    Last Post: 11-27-2008, 07:09 AM
  5. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 07:33 AM

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
  •