Results 1 to 3 of 3
- 02-02-2009, 11:49 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
how use string array while passing to a function
In this code i am reading a file and than using split() method and than i am sending tkn[] array to a call() function there i want to convert string array into integer
while running this code i am getting some errors
ReadFile1.java:36: incompatible types
found : java.lang.String
required: java.lang.String[]
String str[] = tkn[i];
^
ReadFile1.java:37: non-static method call(java.lang.String[]) cannot be referenced from a static context
call(str) ;
^
ReadFile1.java:57: cannot find symbol
symbol : method charAt(int)
location: class java.lang.String[]
char ch =str.charAt(0);
^
ReadFile1.java:58: cannot find symbol
symbol : method parseInt(char)
location: class java.lang.Integer
int tmp = Integer.parseInt(ch);
^
4 errors
import java.io.*;
import java.lang.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReadFile1
{
public static void main(String args[])
{
try
{
FileReader fread=null;
BufferedReader bread = new BufferedReader(new FileReader("new.RAW"));
String line;
while((line=bread.readLine())!=null)
{
String[] tkn =line.split(":");
FileWriter file = new FileWriter("out.txt", true); //bool tells to append
for(int i=0; i<tkn.length;i++)
{
try{
// file.write(" "+tkn[i], 0, tkn[i].length()+1); //(string, start char, end char)
String str[] = tkn[i];
call(str) ;
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}//for
//file.write("\n",0,1);
file.close();
}//while
}catch(Exception e){
System.out.println("Exception: " + e);
}
} //end of main()
void call(String para[])
{
String str[] =para;
char ch =str.charAt(0);
int tmp = Integer.parseInt(ch);
switch(tmp)
{
case 0 :
System.out.println("case 0");
break;
case 1 :
System.out.println("case 1");
break;
case 2 :
System.out.println("case 2");
break;
case 3 :
System.out.println("case 3");
break;
case 4 :
System.out.println("case 4");
break;
case 5 :
System.out.println("case 5");
break;
case 6 :
System.out.println("case 6");
break;
case 7 :
System.out.println("case 7");
break;
case 8 :
System.out.println("case 8");
break;
case 9 :
System.out.println("case 9");
break;
case 10 :
System.out.println("case 10");
break;
case 11 :
System.out.println("case 11");
break;
case 12:
System.out.println("case 12");
break;
case 13 :
System.out.println("case 13");
break;
case 14 :
System.out.println("case 14");
break;
case 15 :
System.out.println("case 15");
break;
/*case "T" :
System.out.println("case t");
break;
case "C1" :
System.out.println("case c1");
break;
case "C2" :
System.out.println("case c2");
break;
case "C3" :
System.out.println("case c3");
break;*/
default:
System.out.println("case default");
break;
}
}
}
- 02-02-2009, 12:29 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Before use, you must initiate the array tkn
- 02-03-2009, 12:44 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
array passing dynamically
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 10-16-2008, 10:29 PM -
[SOLVED] passing array between main and method,vice-versa
By blueyan in forum New To JavaReplies: 5Last Post: 10-04-2008, 11:13 AM -
Passing a Vector object to a function
By evapisces in forum New To JavaReplies: 4Last Post: 09-27-2008, 03:18 AM -
String substring function
By ravian in forum New To JavaReplies: 6Last Post: 01-02-2008, 07:35 PM -
passing an array into an instance
By lockmac in forum New To JavaReplies: 1Last Post: 08-08-2007, 09:35 AM
Bookmarks