I had recently shown a code that was failing, in the end I was able to solve it with the advice of the community and I want to thank you enough, but nevertheless I run into a problem now, the program pulls the error mentioned in the title at the time of compile, when in high school it was not like that ... I do not know if it's a computer problem that I have In addition to wanting to execute it, the following appears
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1041)
at java.awt.Container.add(Container.java:959)
at javax.swing.JFrame.addImpl(JFrame.java:545)
at java.awt.Container.add(Container.java:365)
at based1.<init>(based1.java:143)
at based1.main(based1.java:218)
the code I show you again is
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
public class based1 extends JFrame implements ActionListener{
private JTextField textfield1,textfield2,textfield3,textfield4,textfield5;
private JLabel label1,label2,label3,label4,label5;
private JButton boton1,boton2,boton3,boton4;
private JTextArea texto;
//variables
int id;
int aux1=0,aux2=0,aux3=0,aux4=0,aux5=0;
float aux6=0;
String linea="";
String linea1="";
String linea2="";
String linea3="";
String linea4="";
String linea5="";
public void limpiar(){
textfield1.setText("");
textfield2.setText("");
textfield3.setText("");
textfield4.setText("");
textfield5.setText("");
}
public void tabla1() {
Vector nombresColumnas=new Vector();
nombresColumnas.add("MATRICULA");
nombresColumnas.add("NOMBRES Y APELLIDOS");
nombresColumnas.add("EX1");
nombresColumnas.add("EX2");
nombresColumnas.add("EX3");
DefaultTableModel modelo=new DefaultTableModel(nombresColumnas,0);//0
JTable tabla=new JTable();
tabla.setModel(modelo);
try{ Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e1){
System.out.println(e1.getMessage());}
try{
String password ="";
//nombre de la base de datos Acces con extencion *.mdb o *.accdb
String dbName = "curso1.mdb";
//direccion de la base de datos
String bd= System.getProperty ("user.dir") + "\" + dbName + ";PWD=" + password;
Connection conexion = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ="+bd);
Statement estatuto = conexion.createStatement();
ResultSet rs = estatuto.executeQuery ("select * FROM lista ORDER BY MATRICULA" );
while (rs.next())
{
Vector v;
v= new Vector();
v.add (rs.getString("MATRICULA"));
v.add (rs.getString("NOMBRE"));
v.add (rs.getInt("EX1"));
v.add (rs.getInt("EX2"));
v.add (rs.getInt("EX3"));
modelo.addRow(v);
}
///WHILE
JScrollPane scroll=new JScrollPane (tabla);
this.getContentPane().add (scroll);
scroll.setBounds(350,30,400,300);
scroll.setViewportView(tabla);
scroll.setVisible(true);
estatuto.close();
conexion.close();
}catch(SQLException e1) {System.out.println(e1.getMessage());
}
this.setTitle("Datos Ingresados Correctamente!!!") ;
}
public based1() {
setLayout(null);
label1=new JLabel("Matricula:");
label1.setBounds(5,5,100,30);
add(label1);
textfield1=new JTextField();
textfield1.setBounds(65,10,100,20);
add(textfield1);
label2=new JLabel("Nombres:");
label2.setBounds(5,25,100,30);
add(label2);
textfield2=new JTextField();
textfield2.setBounds(65,32,200,21);
add(textfield2);
label3=new JLabel("Nota 1:");
label3.setBounds(5,53,100,30);
add(label3);
textfield3=new JTextField();
textfield3.setBounds(65,55,50,21);
add(textfield3);
label4=new JLabel("Nota 2:");
label4.setBounds(120,53,100,30);
add(label4);
textfield4=new JTextField();
textfield4.setBounds(170,55,50,21);
add(textfield4);
label5=new JLabel("Nota 3:");
label5.setBounds(225,53,100,30);
add(label5);
textfield5=new JTextField();
textfield5.setBounds(280,55,50,21);
add(textfield5);
boton1=new JButton("Grabar");
boton1.setMnemonic('G');
boton1.setBounds(10,120,100,30);
add(boton1);
boton1.addActionListener(this);
boton2=new JButton("Salir");
boton2.setMnemonic('S');
boton2.setBounds(220,120,100,30);
add(boton2);
boton2.addActionListener(this);
boton2=new JButton("Mostrar");
boton2.setMnemonic('D');
boton2.setBounds(350,120,100,30);
add(boton3);
boton2.addActionListener(this);
boton2=new JButton("Limpiar");
boton2.setMnemonic('D');
boton2.setBounds(500,120,100,30);
add(boton4);
boton2.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==boton1) {
linea="";
linea1=textfield1.getText();
linea2=textfield2.getText();
linea3=textfield3.getText();
linea4=textfield4.getText();
linea5=textfield5.getText();
id=Integer.parseInt(linea1);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e1) {
System.out.println(e1.getMessage());
}
if(id>0) {
try{
String password ="";
String dbName= "curso1.mdb";
String bd = System.getProperty("user.dir") + "\" + dbName + ";PWD=" + password;
Connection conexion = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Acces Driver (*.mdb,*.accdb);DBQ=" +bd);
Statement estatuto= conexion.createStatement();
aux1=Integer.parseInt(linea1);
aux3=Integer.parseInt(linea3);
aux4=Integer.parseInt(linea4);
aux5=Integer.parseInt(linea5);
String q="insert into lista (MATRICULA,NOMBRE,EX1,EX2,EX3)values("+aux1 +", '"+linea2+"',"+aux3+","+aux4+","+aux5+")";
estatuto.executeUpdate(q);
estatuto.close();
conexion.close();
}catch(SQLException e1){
texto.append(e1.getMessage());
}
}
else{
JOptionPane.showMessageDialog(null, "La matricula es incorrecta, debe ser numerica");
}
tabla1();
limpiar();
}
if (e.getSource()==boton2) {
System.exit(0);
}
}
public static void main(String[] args) {
based1 formulario1=new based1();
formulario1.setBounds(1,50,850,450);
formulario1.setVisible(true);
formulario1.setTitle("Formulario de ingreso de Datos Java+Acces");
}
}