Results 1 to 3 of 3
  1. #1
    sks9s9 is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default 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;
    }

    }
    }

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

  3. #3
    sks9s9 is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

Similar Threads

  1. array passing dynamically
    By jazz2k8 in forum Advanced Java
    Replies: 2
    Last Post: 10-16-2008, 11:29 PM
  2. Replies: 5
    Last Post: 10-04-2008, 12:13 PM
  3. Passing a Vector object to a function
    By evapisces in forum New To Java
    Replies: 4
    Last Post: 09-27-2008, 04:18 AM
  4. String substring function
    By ravian in forum New To Java
    Replies: 6
    Last Post: 01-02-2008, 08:35 PM
  5. passing an array into an instance
    By lockmac in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 10:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •