galera, o que tem de errado no meu código? Se alguem puder me ajudar eu agradeço
ele lê certinho o arquivo xls, porém quando vai salvar em txt dá esse erro:
Exception in thread "main" java.lang.NullPointerException
at gerarscript.Main.main(Main.java:41)
Ta ai o código
Mainpackage gerarscript;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Main {
public static void main(String[] args) throws IOException, BiffException, ClassNotFoundException {
GerarTxt gerarTxt = null;
Workbook workbook = Workbook.getWorkbook(new File("C:/Users/David/cibele.xls"));
/* pega a primeira planilha dentro do arquivo XLS */
Sheet sheet = workbook.getSheet(0);
//Pega a quantidade de linhas da planilha
int linhas = sheet.getRows();
for(int i = 1; i < 2; i++){ // Aqui eu alterei a variável linhas só para testar, coloquei o 2 no lugar
/* pega os valores das células como se numa matriz */
Cell f1 = sheet.getCell(5,i);
Cell g1 = sheet.getCell(6,i);
Cell h1 = sheet.getCell(7,i);
Cell i1 = sheet.getCell(8,i);
/* pega os conteúdos das células */
String col6 = f1.getContents();
String col7 = g1.getContents();
String col8 = h1.getContents();
String col9 = i1.getContents();
gerarTxt.Gravar(" on mouseEnter me\n"
+ " cursor 280\n"
+ " set the member of sprite the currentSpriteNum to member \""+col9+"\"\n"
+ "MAutores(\""+col7+"\")\n"
+ "end\n"
+ "\n"
+ "on mouseLeave me\n"
+ "set the member of sprite the currentSpriteNum to member \""+col8+"\"\n"
+ "put \" \" into member \"txtAutor\"\n"
+ "cursor -1\n"
+ "end\n"
+ "\n"
+ "on mouseDown me\n"
+ "cursor -1\n"
+ "global abc\n"
+ "set abc to \""+col6+"\"\n"
+ "cursor 4\n"
+ "puppettransition 23 \n"
+ "go to marker (\"MostraPDFs\")\n"
+ "end\n");
}
workbook.close();
}
}
package gerarscript;
import java.io.FileWriter;
import javax.swing.JOptionPane;
public class GerarTxt {
public void Gravar(String texto){
String conteudo = texto;
try{
// o true significa q o arquivo será constante
FileWriter x = new FileWriter("C:/Users/David/script/teste1.txt",true);
conteudo += "\n\r"; // criando nova linha e recuo no arquivo
x.write(conteudo); // armazena o texto no objeto x, que aponta para o arquivo
x.close(); // cria o arquivo
JOptionPane.showMessageDialog(null,"Arquivo gravado com sucesso","Concluído",JOptionPane.INFORMATION_MESSAGE);
}
// em caso de erro apreenta mensagem abaixo
catch(Exception e){
JOptionPane.showMessageDialog(null,e.getMessage(),"Atenção",JOptionPane.WARNING_MESSAGE);
}
}
}