-2
I am developing software for a video rental company with Pattern MVC (Model-view-controller) design with the Java Persistent Api Framework and the XML (Generic Markup Extensible Language).
My problem is this: When I log in to my system login screen, a java.lan.nullException happens, because a String is coming as null.
How can I resolve this java.lang.nullException problem?
Classgrade: String class Path that is coming null.
package classes_utilitarias;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.JDesktopPane;
public class AlteraFundo extends JDesktopPane {
Image img;
public AlteraFundo(String caminho){
File imagem = new File(caminho);
try
{
img = javax.imageio.ImageIO.read(imagem);
}
catch(Exception e){}//do nothing
}
}
Main Screen:
package formularios;
import classes_persistencia.AcessoDAO;
import classes_registros.Acesso;
import java.awt.BorderLayout;
import java.beans.PropertyVetoException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import classes_utilitarias.AlteraFundo;
import classes_utilitarias.GravaPosicao;
import java.awt.Color;
import java.awt.Component;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JInternalFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
private static String Caminho_fundo = "";
private void initComponents() {
try{
mdi_principal = new classes_utilitarias.AlteraFundo(GravaPosicao.le_conf_geral("Caminho_fundo"));
tool_principal = new javax.swing.JToolBar();
Gravaposition class:
/Método SalvaPosicao, recebe o nome do Frm que está chando e a posição dele, grava no arquivo
public class GravaPosicao {
public static void salvaPosicao(String nomeFrm, Point posicao){
String newLine = System.getProperty("line.separator");
String gravaPosicao= ""+ nomeFrm +":"+ String.valueOf(posicao.x) +"x"+ String.valueOf(posicao.y)+newLine;
//System.out.print(gravaPosicao);
try{
UtilsArquivo.salvar("c:/Singelo/position.inf", gravaPosicao, true);
}
catch(Exception e){
e.printStackTrace();
}
}
public static String le_conf_geral(String nome_ctxt) throws FileNotFoundException, IOException{
String ler;
String []info;
String retorno= null;
try{
File arquivo= new File("c:/Singelo/config.inf");
if(!(arquivo.exists())){
return null;
}
FileReader leitura2= new FileReader("c:/Singelo/config.inf");
BufferedReader leitor2= new BufferedReader(leitura2);
while((ler = leitor2.readLine()) != null){
info=ler.trim().split(">");
if(info[0].equals(nome_ctxt)){
retorno= info[1];
break;
}
}
leitura2.close();
}
catch(Exception p){
p.printStackTrace();
}
return retorno;
}
}
Error log:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.io.File.<init>(File.java:277)
at classes_utilitarias.AlteraFundo.<init>(AlteraFundo.java:21)
at formularios.FrmPrincipal.initComponents(FrmPrincipal.java:91)
at formularios.FrmPrincipal.<init>(FrmPrincipal.java:64)
at formularios.FrmLogin.ir(FrmLogin.java:239)
at formularios.FrmLogin.bt_entrarActionPerformed(FrmLogin.java:137)
at formularios.FrmLogin.access$000(FrmLogin.java:20)
at formularios.FrmLogin$1.actionPerformed(FrmLogin.java:69)
@Guilhermenascimento Your help from Bin folder solved the problem here and that method worked very well! Thanks and thanks!
– Igor Contini
@Math Thanks you too for helping me!
– Igor Contini
I replied @Igorcontini could mark as correct?
– Guilherme Nascimento
@Guilhermenascimento Of course I did! Look I didn’t answer you before because I didn’t have internet and because of personal problems...
– Igor Contini