I've been messing around with Java for the last two weeks and created this simple flat file database login, but I've stumbled across this error that has stumped me.
Basically, I'm trying to load a text file, break down the string using the StringTokenizer,
and load it into an 2D Array.
Main
loginController
Basically, I'm trying to load a text file, break down the string using the StringTokenizer,
and load it into an 2D Array.
Code:
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at loginController.loadUserDatabase(loginController.java:36)
at FinalED.main(FinalED.java:52)
Press any key to continue...
Main
Code:
public class FinalED
{
loginController login = new loginController();
public static void main(String[] args)
{
login.loadUserDatabase();
}
loginController
Code:
import java.util.*;
import java.io.*;
public class loginController {
public static String[][] credentials = new String[20][3];
public static void loadUserDatabase()
{
try
{
Scanner loadUserDatabase = new Scanner(new File("users.db"));
while (loadUserDatabase.nextLine() != null)
{
String dbRecord = loadUserDatabase.nextLine();
StringTokenizer dbRead = new StringTokenizer(dbRecord, ":");
for(int i=0;i<3;i++)
{
//Username
credentials[i][0]= dbRead.nextToken(); //line 36
//Password
credentials[i][1]= dbRead.nextToken();
//Access Level
credentials[i][2]= dbRead.nextToken();
}
}
}
catch(IOException e)
{
}
}
//Simple debug
public static void checkCredentials()
{
System.out.println(credentials[0][0] +credentials[0][1] +credentials[0][2] );
}
}