Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-18-2008, 06:27 PM
Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
CloseQuarters is on a distinguished road
Default Please Help new to Java and keep getting error
Ok so im new to Java and i keep getting this error everytime i try to run my script. The error is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at patient.patient_inform.add_patient(patient.java:98 )
at patient.patient.main(patient.java:26)

The error occurs at different points depending on what data i enter when i run my code.

here is my code Please Help



import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;
public class patient

{

public static void main(String[] args)
{
int option;
String value;
patient_inform patient = new patient_inform ();
patient.start_system();
value = patient.menu();
option = Integer.parseInt(value);
while(option!=4)
{
if(option==1)
{
patient.add_patient();
}
else if (option==2)
{
patient.modify_patient();

}
else if (option==3)
{
patient.patient_report();
value = patient.menu();
option =Integer.parseInt(value);
}
}
//while loop
patient.exit_system();
System.exit(0);
}
//main method
}
class patient_inform
{
int count = -1, i;
String lasname[] = new String[i];
String firname[] = new String[i];
int age[] = new int[i];
int rstat[] = new int[i];
String romnum[] = new String[i];
String codes[] = new String[i];
String gendr[] = new String[i];

void start_system()
{
String newLine;
try
{
BufferedReader Patient_file = new BufferedReader(new FileReader("patient.dat"));
while ((newLine = Patient_file.readLine()) != null)
{
StringTokenizer delimiter = new StringTokenizer(newLine, "#");
count=count+1;
lasname[count] = delimiter.nextToken();
firname[count] = delimiter.nextToken(); rstat[count] = Integer.parseInt(delimiter.nextToken());
romnum[count] = delimiter.nextToken();
gendr[count] = delimiter.nextToken();
age[count] = Integer.parseInt(delimiter.nextToken());
}
Patient_file.close();
}
catch (IOException error)
{
System.out.println("Error on file rad"+ error);
}
}

String menu()
{
String rnum;
String output = "Delaware Medical Hospital" + "\n" + "\n" +
"1. Add/Modify the Patient Data" + "\n" +
"2. Add/Modify the Surgical Data" + "\n" +
"3. Report the Section" + "\n" +
"4. Exit the System" + "\n" + "\n" +
"Make selection";
rnum = JOptionPane.showInputDialog(null, output, "", JOptionPane.QUESTION_MESSAGE);;
return rnum;
}
void add_patient()
{
String svalue,Output;
count=count+1;
Output = "Enter patients last name";
lasname[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients first name";
firname[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients Gender (m for Male or f for Female only!";
gendr[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients age";
svalue = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
age[count] = Integer.parseInt(svalue);
Output = "Enter patients surgical status, 1 for surgical patient and 2 for non-surgical patient";
svalue = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
rstat[count] = Integer.parseInt(svalue);
Output = "Enter patients room status, I for in-patient, O for out-patient";
romnum[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
}
void modify_patient()
{
int poption;
String modnum;
String output = "Modify Patient Menu" + "\n" + "\n" +
"1. Add the Patient" + "\n" +
"2. Delete the Patient" + "\n" +
"3. Modify the Patient" + "\n" +
"4. Leave the Patient Menu" + "\n" + "\n" +
"Make selection";
modnum = JOptionPane.showInputDialog(null, output, "", JOptionPane.QUESTION_MESSAGE);
poption = Integer.parseInt(modnum);
if (poption ==1)
{
String rvalu,Output;
count=count+1;
Output = "Enter patients last name";
lasname[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients first name";
firname[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients Gender (m for Male or f for Female only!";
gendr[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
Output = "Enter patients age";
rvalu = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
age[count] = Integer.parseInt(rvalu);
Output = "Etner patients surgical status, 1 for surgical patient and 2 for non-surgical patient";
rvalu = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
rstat[count] = Integer.parseInt(rvalu);
Output = "Enter patients room status, I for in-patient, O for out-patient";
romnum[count] = JOptionPane.showInputDialog(null, Output, "", JOptionPane.QUESTION_MESSAGE);
}

}

void patient_report()
{
System.out.println("All Patient Information");
for (i=0; i<=count; ++i);
{
System.out.println(lasname[i]+ ""+firname[i]+""+gendr[i]+""+age[i]+""+rstat[i]+""+romnum[i]);
}
}
void exit_system()
{
try {
BufferedWriter Patientfile = new BufferedWriter(new FileWriter("patient.dat"));;
for(i=0; i<=count; ++i);;
{
Patientfile.write(lasname[i]+ "#"+firname[i]+"#"+gendr[i]+"#"+age[i]+"#"+rstat[i]+"#"+romnum[i]);
Patientfile.newLine();
}
Patientfile.close();
}
catch (IOException error)
{
System.out.println("Eror on fileds write"+ error);
}
}
}
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-18-2008, 07:39 PM
CJSLMAN's Avatar
Moderator
 
Join Date: Oct 2008
Location: Mexico
Posts: 1,149
Rep Power: 2
CJSLMAN is on a distinguished road
Default hhhmmm...
Not sure, but is variable "i" initialized in the patient_inform class?
Code:
class patient_inform
{
int count = -1, i; //< - not initialized 
String lasname[] = new String[i]; //<- i being used
.
.
.
Luck,
CJSL
__________________
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Hotspot Error prashantredhat Advanced Java 0 07-18-2008 07:38 AM
How to get error codes using java program kasipandian Web Frameworks 10 05-25-2008 05:00 PM
java error message baileyr New To Java 2 01-23-2008 03:47 AM
error with import java.io.* osval New To Java 4 08-06-2007 09:12 PM
error in Java files ai_2007 Advanced Java 1 07-31-2007 12:14 PM


All times are GMT +2. The time now is 01:54 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org