Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

VECTOR ERROR IN I/O STREAM  RSS feed

 
nabi bux
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi.
Every Body when i compile and run the following exception
are throw by the interprter
please help me what is the mistake i have
i want to use vector to store data in file
i want to use vector to retrieve data from the file
this is my algrothim i have project from university to
establish data base i thing vector is best way to manipulate
data into or out of the file.



Thanks in advance!
ali //first input
ali // second input

ali // third input
ali // foruth input after i the following exception are throwm

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.setElementAt(Vector.java:482)
at Showingvector1.main(Showingvector1.java:37)
Press any key to continue . . .



import java.util.*;
import java.io.*;
class Add
{
String s;
String s1;
public Add(String m,String mn)
{
s=m+"\n";
s1=mn+"\n";
}
public String toString()
{
return s+s1;
} }
class Showingvector1
{
public static void main(String sm[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String st,st1;
FileOutputStream f=new FileOutputStream("jeay.txt");
DataOutputStream dt=new DataOutputStream(f);
Vector v=new Vector();int pos=0;
while(true){
st=br.readLine();
st1=br.readLine();
if (st=="Exit")
break;
Add ad=new Add(st,st1);
if(pos==0)
v.addElement(ad);
else
v.setElementAt(ad,pos);
Add ar=(Add)v.elementAt(pos);
dt.writeUTF(ar.s);
dt.writeUTF(ar.s1);
pos++;
} }


}
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question more than once in the same forum (especially after your question has been answered in a previous post). I'm going to close this topic and delete the previous post that has no replies. Follow up in this topic.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!