Results 1 to 5 of 5
- 01-01-2011, 10:29 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
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
- 01-01-2011, 10:35 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
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:
Of course that doesn't work; supply a two dimensional array as a parameter, not just one String element.Java Code:arrange(arr[12][5]); // <-- here
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-01-2011, 10:45 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
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?
- 01-01-2011, 10:48 AM #4
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
pass in the array
because you have defined your function to take in a 2D string array , as inJava Code:arrange(arr);
if you do thisJava Code:public static void arrange(String[][] arr1)
you are passing in a string that is contained in row 11 item 6 of arr array, which is wrong.Java Code:arrange(arr[12][5]);
- 01-01-2011, 10:52 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Problem with compiling: cannot be applied to (java.lang.String)
By sjaakie in forum New To JavaReplies: 5Last Post: 10-10-2010, 12:17 AM -
WordSearchAPI cannot be applied to (java.lang.String)
By LordBios in forum New To JavaReplies: 4Last Post: 01-29-2010, 09:57 PM -
[SOLVED] operator / cannot to applied to java.lang.string,int
By tpyq in forum NetBeansReplies: 3Last Post: 12-01-2008, 05:40 AM -
Error Message: operator * cannot be applied to java.lang.String, int
By MICHAELABICK in forum Java AppletsReplies: 4Last Post: 11-27-2008, 06:09 AM -
Error: cannot be applied to (java.lang.String)
By carl in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:33 AM


LinkBack URL
About LinkBacks


Bookmarks