Merhaba arkadaşlar, dosyadan verileri okuyup boşluklarla ayrılmış olan verimi diziye atmak istiyorum ama java.lang.NullPointerException hatası alıyorum kod burada nerede hata yapıyor olabilirm
dene.txt şu şekilde a b c d e f . . . . . .
public static void main(String[] args) throws FileNotFoundException, IOException { final BufferedReader in=new BufferedReader(new FileReader("C:\\dene.txt")); String str; String[] oku = null; String[] parts = null; int i=0; while((str=in.readLine())!=null) { oku=str.split(" "); parts=oku[1]; System.out.println(oku[1]); i++; } for(int j=0;j<=i;j++) System.out.println(parts[j]); }
< Bu mesaj bu kişi tarafından değiştirildi afearless -- 27 Mart 2015; 2:52:35 >
En alttaki for da j<=i demişsin, j<i dersen büyük ihtimalle düzelicek. parts[j] ile girerken son index +1 vermiş oluyorsun, o yüzden hata alıyorsun. Kodu çok incelemedim de muhtemelen budur.
dene.txt şu şekilde
a b c
d e f
. . .
. . .
public static void main(String[] args) throws FileNotFoundException, IOException {
final BufferedReader in=new BufferedReader(new FileReader("C:\\dene.txt"));
String str;
String[] oku = null;
String[] parts = null;
int i=0;
while((str=in.readLine())!=null)
{
oku=str.split(" ");
parts=oku[1];
System.out.println(oku[1]);
i++;
}
for(int j=0;j<=i;j++)
System.out.println(parts[j]);
}
< Bu mesaj bu kişi tarafından değiştirildi afearless -- 27 Mart 2015; 2:52:35 >