Bom pessoal não sei se pelo titulo deu pra entender o que eu quizer dizer então vou dizer novamente.
Estou lendo um arquivo .TXT e salvando ele em um vetor de String[] quando eu percorro todo esse vetor dentro do meu metodo Le(); mostra tudo bonitinho...
porém ao fazer um método separado para mostrar o que tem dendo dessa String[] da o erro de "Exception in thread "main" java.lang.NullPointerException"
Codigo do metrodo Le();
public void Le() throws FileNotFoundException, IOException {
FileReader ordtopin = new FileReader(new File("C:\\Users\\User\\Documents\\NetBeansProjects\\Arquivo\\ordtop.in"));
BufferedReader leitor = new BufferedReader(ordtopin);
String linha = null;
String linha1;
VerQuantidadeLinhas();
int count = 0;
int opcount = 0;
linha1 = leitor.readLine();
QtdTarefaPrivate = Integer.parseInt(linha1); //Só para nao mexer futuramente
String[] tarefas = new String[QtdTarefaPrivate];
String[] Op = new String[QtdLinhas];
while (!"0 0".equals(linha)) {
linha = leitor.readLine();
//System.out.println("Linha : "+linha);
if (count < 12) {
tarefas[count] = linha;
count++;
} else {
Op[opcount] = linha;
opcount++;
}
}
leitor.close();
ordtopin.close();
}
public void MostraTarefas() {
int c = 0;
System.out.println("oi" + tarefas[1]);
int QtdTarefa = QtdTarefaPrivate;
while (QtdTarefa != 0) {
System.out.println(tarefas[c]);
c++;
QtdTarefa--;
}
}
package ordenaçãotopologica;
import java.io.*;
public class LeEscreveArquivo {
public String[] tarefas;
public String[] Op;
private int QtdTarefaPrivate;
private int QtdLinhas;
public void Le() throws FileNotFoundException, IOException {
FileReader ordtopin = new FileReader(new File("C:\\Users\\User\\Documents\\NetBeansProjects\\Arquivo\\ordtop.in"));
BufferedReader leitor = new BufferedReader(ordtopin);
String linha = null;
String linha1;
VerQuantidadeLinhas();
int count = 0;
int opcount = 0;
linha1 = leitor.readLine();
QtdTarefaPrivate = Integer.parseInt(linha1); //Só para nao mexer futuramente
String[] tarefas = new String[QtdTarefaPrivate];
String[] Op = new String[QtdLinhas];
while (!"0 0".equals(linha)) {
linha = leitor.readLine();
//System.out.println("Linha : "+linha);
if (count < 12) {
tarefas[count] = linha;
count++;
} else {
Op[opcount] = linha;
opcount++;
}
}
leitor.close();
ordtopin.close();
}
public void Escreve() throws IOException {
FileWriter ordtopout = new FileWriter(new File("C:\\Users\\User\\Documents\\NetBeansProjects\\Arquivo\\ordtop.out"), true);
FileWriter ordtoptxt = new FileWriter(new File("C:\\Users\\User\\Documents\\NetBeansProjects\\Arquivo\\ordtop1.txt"), true);
PrintWriter saidaout = new PrintWriter(ordtopout, true);
PrintWriter saidatxt = new PrintWriter(ordtoptxt, true);
saidaout.println("Teste");
//saidatxt.println("Teste");
saidaout.close();
saidatxt.close();
ordtopout.close();
ordtoptxt.close();
System.out.println("Salvo");
}
public void MostraTarefas() {
int c = 0;
System.out.println("oi" + tarefas[1]);
int QtdTarefa = QtdTarefaPrivate;
while (QtdTarefa != 0) {
System.out.println(tarefas[c]);
c++;
QtdTarefa--;
}
}
private void VerQuantidadeLinhas() throws FileNotFoundException, IOException {
FileReader ordtopin = new FileReader(new File("C:\\Users\\User\\Documents\\NetBeansProjects\\Arquivo\\ordtop.in"));
BufferedReader leitor = new BufferedReader(ordtopin);
int v = 0;
String linha = null;
while (!"0 0".equals(linha)) {
linha = leitor.readLine();
v++;
}
QtdLinhas = v - QtdTarefaPrivate - 1;
}
private void MostraOperações() {
int c = 0;
int linhas = QtdLinhas;
while (linhas != 0) {
System.out.println(Op[c]);
c++;
linhas--;
}
}
}
package ordenaçãotopologica;
import java.io.IOException;
public class OrdenaçãoTopologicaMain {
public static void main(String[] args) throws IOException {
LeEscreveArquivo teste = new LeEscreveArquivo();
teste.Le();
teste.Escreve();
teste.MostraTarefas();
}
}
Exception in thread "main" java.lang.NullPointerException
at ordenaçãotopologica.LeEscreveArquivo.MostraTarefas(LeEscreveArquivo.java:56)
at ordenaçãotopologica.OrdenaçãoTopologicaMain.main(OrdenaçãoTopologicaMain.java:10)
Java Result: 1
Tava pensando é melhor salvar essa string em NOS... ou deixa em vetor mesmo?