d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Compiling Error > Can't Find It T_t
Add Reply New Topic New Poll
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 19 2013 10:44pm
import java.util.*;
import java.io.*;

public class Lab10{

public static void main (String[] args)
throws FileNotFoundException
{
System.out.println("Please Enter the file name");
File fileInput = new File(userInput());
String[] arr = new String [countString(fileInput)];
storeFileInStringArr(fileInput.arr);
stringRemove(arr);
}
public static String userInput()
{
Scanner input = new Scanner(System.in);
return input.next();
}

public static int countString(File fileName)
throws FileNotFoundException
{
Scanner fileInput = new Scanner(fileName);
int count = 0;
String tmp;
while (fileInput.hasNext())
{
fileInput.next();
count++;

}
}
public static void storeFileInStringArr(File fileName, String [] arr)
throws FileNotFoundException
{
Scanner fileInput = new Scanner(fileName);
int i;
for ( i = 0; i<arr.length; i++);
{
arr[i] = fileInput.next();
}
return;
}

public static void stringRemove(String[] arr)
{
int i;
for (i=0; i<arr.length; i++)
{
arr[i] = arr[i].replaceAll("[.,;:?!\"\'()]","");
System.out.println(arr[i]);
}
}
}

When I compile It, I get:
Lab10.java:12: error: cannot find symbol
storeFileInStringArr(fileInput.arr);
^
symbol: variable arr
location: variable fileInput of type File
1 error

Where is my mistake?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 19 2013 10:49pm
did you even read the error?

Quote
Lab10.java:12: error: cannot find symbol
storeFileInStringArr(fileInput.arr);
^
symbol: variable arr
location: variable fileInput of type File
1 error


Quote
public static void storeFileInStringArr(File fileName, String [] arr)


does that look right to you?

This post was edited by carteblanche on Nov 19 2013 10:51pm
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 19 2013 11:02pm
Quote (carteblanche @ Nov 19 2013 08:49pm)
did you even read the error?





does that look right to you?


I dont see it for some reason... please explain
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 19 2013 11:13pm
Quote (Chesse @ Nov 20 2013 12:02am)
I dont see it for some reason... please explain


Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Nov 19 2013 11:14pm
This method takes 2 variables, yet you are only passing in 1
Member
Posts: 6,175
Joined: Sep 4 2009
Gold: Locked
Trader: Scammer
Nov 20 2013 01:50am
oh wow... forgive me :l

I finally finished the coding and it compiled perfectly.
However I got this when I tried inputting a file

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Lab10.storeFileInStringArr(Lab10.java:44)
at Lab10.main(Lab10.java:12)

What does this mean?
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Nov 20 2013 05:27am
Do you never google anything?

Do yourself a favor, google the phrase "array index out of bounds"
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Nov 20 2013 08:18am
It would help to use an IDE. It will show you exactly where the errors are without even having to compile.

As for the ArrayIndexOutOfBoundsException

Code
public static int countString(File fileName)
throws FileNotFoundException
{
Scanner fileInput = new Scanner(fileName);
int count = 0;
String tmp;
while (fileInput.hasNext())
{
fileInput.next();
count++;

}
}


This function doesn't return anything

change it to
Code
public static int countString(File fileName)
throws FileNotFoundException
{
Scanner fileInput = new Scanner(fileName);
int count = 0;
String tmp;
while (fileInput.hasNext())
{
fileInput.next();
count++;

}
return count;
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll