Olá a todos. Estou fazendo um programa mas quando eu rodo ele aparece o seguinte conjunto de erros:
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
at conversao.convertfloat(conversao.java:214)
at telaframe2$3.actionPerformed(telaframe2.java:263)
o código do programa esta abaixo (sao duas classes)
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
//import javax.xml.crypto.Data;
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JPasswordField;
import java.awt.Dimension;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.awt.*;
import java.lang.Object;
import java.lang.NullPointerException;
public class conversao {
String [][] endereco;
OutputStream [] saindo;
int E = 0;
public String[][] enderecando(String O)
{
endereco = new String[122][6];
String nome = "";
for (int i = 1; i < 123 ;i++)
{
if (i < 10)
{
for (int j = 0; j < 6; j++)
{
String importante = "";
switch (j)
{
case 0:
{
importante = "FX";
break;
}
case 1:
{
importante = "FY";
break;
}
case 2:
{
importante = "FZ";
break;
}
case 3:
{
importante = "MX";
break;
}
case 4:
{
importante = "MY";
break;
}
case 5:
{
importante = "MZ";
break;
}
}
nome = "Riser30_e00"+i+"_" + importante +".dac" ;
endereco[i-1][j] = O + nome;
}
}
if (i > 9 & i < 100)
{
for (int j = 0; j < 6; j++)
{
String importante = "";
switch (j)
{
case 0:
{
importante = "FX";
break;
}
case 1:
{
importante = "FY";
break;
}
case 2:
{
importante = "FZ";
break;
}
case 3:
{
importante = "MX";
break;
}
case 4:
{
importante = "MY";
break;
}
case 5:
{
importante = "MZ";
break;
}
}
nome = "Riser30_e0"+i+"_" + importante + ".dac" ;
endereco[i-1][j] = O + nome;
}
}
if (i > 99)
{
for (int j = 0; j < 6; j++)
{
String importante = "";
switch (j)
{
case 0:
{
importante = "FX";
break;
}
case 1:
{
importante = "FY";
break;
}
case 2:
{
importante = "FZ";
break;
}
case 3:
{
importante = "MX";
break;
}
case 4:
{
importante = "MY";
break;
}
case 5:
{
importante = "MZ";
break;
}
}
nome = "Riser30_e"+i+"_" + importante + ".dac" ;
endereco[i-1][j] = O + nome;
}
}
}
return endereco;
}
public void criaarquivosaida (String L)
{
saindo = new OutputStream[732];
try {
File filesaida = new File(L);
saindo[E] = new FileOutputStream(filesaida);
// saindo[0].write(floatToArrayByte(3599));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException g) {
// TODO Auto-generated catch block
g.printStackTrace();
}
E++;
}
public void convertfloat (float dadofloat)
{
for (int E = 0; E < 732 ; E++)
{
try {
saindo[0].write(floatToArrayByte(3599));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
catch (NullPointerException h){
//TODO Auto-generated catch block
h.printStackTrace();
}
}
}
public void convertint (int dadoint)
{
try {
File file = new File(endereco[0][0]);
OutputStream output = new FileOutputStream(file);
byte[] floatValue = floatToArrayByte(3599);
//output.write(intToArrayByte(32000));
output.write(intToArrayByte(3599));
//output.write(charToByte(dadoChar));
output.write(floatToArrayByte(3599));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void convertchar (char dadochar)
{
}
static float byteArraytoFloat(byte[] aBytes)
// OUTPUT: equivalent float value
{
int tempbits = ((0xff & aBytes[0]) | ((0xff & aBytes[1]) << 8)
| ((0xff & aBytes[2]) << 16) | ((0xff & aBytes[3]) << 24));
float ff = Float.intBitsToFloat(tempbits);
return ff;
}
static byte[] floatToArrayByte(float value)
// OUTPUT: equivalent float value
{
int tempbits = Float.floatToIntBits(value);
byte[] bytes = new byte[4];
int i;
for (i = 0; i < 4; i++) {
bytes[3 - i] = (byte) ((tempbits >>> ((4 - i - 1) * 8)) & 0xFF);
}
return bytes;
}
static byte[] intToArrayByte(int value)
// OUTPUT: equivalent float value
{
byte[] bytes = new byte[2];
int i;
for (i = 0; i < 2; i++) {
bytes[1 - i] = (byte) ((value >>> ((2 - i - 1) * 8)) & 0xFF);
}
return bytes;
}
static int byteArraytoInt(byte[] aBytes)
{
int tempbits;
if (aBytes[1] < 0) {
tempbits = ((0xff & aBytes[0]) | ((0xff & aBytes[1]) << 8)
| (0xff << 16) | (0xff << 24));
} else {
tempbits = ((0xff & aBytes[0]) | ((0xff & aBytes[1]) << 8));
}
return tempbits;
}
static char bytetoChar(byte ascii)
{
return (char) ascii;
}
static byte charToByte(char unicode)
{
return (byte) unicode;
}
}
e a outra classe
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JPasswordField;
import java.awt.Dimension;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import java.awt.*;
import java.lang.Object;
import java.lang.NullPointerException;
public class telaframe2 extends JDesktopPane {
String [] U;
String V;
private static final long serialVersionUID = 1L;
private JButton jButton = null;
private JLabel jLabel = null;
private JTextField jTextField = null;
private JButton jButton1 = null;
private JTextField jTextField1 = null;
private JLabel jLabel1 = null;
private JLabel jLabel11 = null;
private JLabel jLabel111 = null;
private JLabel jLabel112 = null;
private JLabel jLabel113 = null;
private JTextField jTextField11 = null;
private JLabel jLabel114 = null;
private JTextField jTextField111 = null;
private JTextField jTextField1111 = null;
private JTextField jTextField2 = null;
private JTextField jTextField3 = null;
private JTextField jTextField4 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JButton jButton11 = null;
private JButton jButton111 = null;
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(360, 90, 77, 31));
jButton.setText("Abrir");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Open abrir = new Open();
//abrir.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String k = abrir.analyzePath();
jTextField.setText(k);
k = k + "\\";
String [] H;
H = new String[122];
H = abrir.analyzePath2(k);
//String [] U;
U = new String[122];
for (int i = 0; i<122; i++)
{
U[i] = k + H[i];
U[i] = U[i].replaceAll("\\\\", "\\\\\\\\");
//System.out.printf("%s \n", U[i]);
}
}
});
}
return jButton;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(106, 90, 240, 20));
}
return jTextField;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(360, 210, 77, 31));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Open abrir = new Open();
//abrir.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String k = abrir.analyzePath();
jTextField1.setText(k);
V = k + "\\";
//String [] H;
//H = new String[732];
//H = abrir.analyzePath2(k);
//V = new String[122];
//for (int i = 0; i<122; i++)
//{
//V[i] = k + H[i];
V = V.replaceAll("\\\\", "\\\\\\\\");
//System.out.printf("%s", V);
//}
}
});
jButton1.setText("Abrir");
}
return jButton1;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(106, 210, 240, 20));
}
return jTextField1;
}
/**
* This method initializes jTextField11
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField11() {
if (jTextField11 == null) {
jTextField11 = new JTextField();
jTextField11.setBounds(new Rectangle(60, 315, 94, 20));
jTextField11.setText("");
}
return jTextField11;
}
/**
* This method initializes jTextField111
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField111() {
if (jTextField111 == null) {
jTextField111 = new JTextField();
jTextField111.setBounds(new Rectangle(60, 345, 94, 20));
}
return jTextField111;
}
/**
* This method initializes jTextField1111
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1111() {
if (jTextField1111 == null) {
jTextField1111 = new JTextField();
jTextField1111.setBounds(new Rectangle(60, 375, 94, 20));
}
return jTextField1111;
}
/**
* This method initializes jTextField2
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setBounds(new Rectangle(60, 405, 94, 20));
}
return jTextField2;
}
/**
* This method initializes jTextField3
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setBounds(new Rectangle(60, 435, 94, 20));
}
return jTextField3;
}
/**
* This method initializes jTextField4
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField4() {
if (jTextField4 == null) {
jTextField4 = new JTextField();
jTextField4.setBounds(new Rectangle(60, 465, 94, 20));
}
return jTextField4;
}
/**
* This method initializes jButton11
*
* @return javax.swing.JButton
*/
private JButton getJButton11() {
if (jButton11 == null) {
jButton11 = new JButton();
jButton11.setBounds(new Rectangle(296, 456, 91, 26));
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String vetorfx = jTextField11.getText();
double menosfx = Double.parseDouble(vetorfx);
String vetorfy = jTextField111.getText();
double menosfy = Double.parseDouble(vetorfy);
String vetorfz = jTextField1111.getText();
double menosfz = Double.parseDouble(vetorfz);
String vetormx = jTextField2.getText();
double menosmx = Double.parseDouble(vetormx);
String vetormy = jTextField3.getText();
double menosmy = Double.parseDouble(vetormy);
String vetormz = jTextField4.getText();
double menosmz = Double.parseDouble(vetormz);
// System.out.printf("teste %s\n%f\n%f\n%f\n%f\n%f",menosfx,
// menosfy,menosfz,menosmx,menosmy,menosmz);
abrindo comeco = new abrindo();
conversao primeiro = new conversao();
String [][] endereco1;
endereco1 = new String[122][6];
endereco1 = primeiro.enderecando(V);
int p = 0;
for (int i = 0; i < 122 ; i++)
{
for (int j = 0 ; j <6 ; j++)
{
primeiro.criaarquivosaida(endereco1[i][j]);
}
}
primeiro.convertfloat(3599);
// primeiro.convertfloat(1);
// primeiro.convertfloat(0);
// primeiro.convertfloat(1);
// for (int linha = 0; linha < 122 ; linha++)
// {
// for (int coluna = 0; coluna < 6 ; coluna++)
// {
// primeiro.enderecando(V);
// primeiro.convertfloat(3599);
// }
// }
// for (int i = 0; i < 122; i++)
// {
// comeco.openFile(U[i],i);
// comeco.readRecords();
// }
// primeiro.enderecando(V);
// primeiro.convertfloat(5);
}
});
jButton11.setText("Converter");
}
return jButton11;
}
/**
* This method initializes jButton111
*
* @return javax.swing.JButton
*/
private JButton getJButton111() {
if (jButton111 == null) {
jButton111 = new JButton();
jButton111.setBounds(new Rectangle(413, 456, 91, 26));
jButton111.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextField11.setText("");
jTextField111.setText("");
jTextField1111.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField.setText("");
jTextField1.setText("");
}
});
jButton111.setText("Limpar");
}
return jButton111;
}
/**
* @param args
*/
public void main(String[] args) {
// TODO Auto-generated method stub
}
/**
* This is the default constructor
*/
public telaframe2() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(37, 465, 17, 16));
jLabel3.setText("Mz");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(37, 435, 17, 16));
jLabel2.setText("My");
jLabel114 = new JLabel();
jLabel114.setBounds(new Rectangle(53, 289, 189, 16));
jLabel114.setText("Valores de Entrada");
jLabel113 = new JLabel();
jLabel113.setBounds(new Rectangle(37, 405, 17, 16));
jLabel113.setText("Mx");
jLabel112 = new JLabel();
jLabel112.setBounds(new Rectangle(37, 375, 13, 16));
jLabel112.setText("Fz");
jLabel111 = new JLabel();
jLabel111.setBounds(new Rectangle(37, 345, 13, 16));
jLabel111.setText("Fy");
jLabel11 = new JLabel();
jLabel11.setBounds(new Rectangle(37, 315, 13, 16));
jLabel11.setText("Fx");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(174, 233, 113, 16));
jLabel1.setText("Diretório de Saída");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(174, 113, 113, 16));
jLabel.setText("Diretório de Entrada");
this.setSize(534, 531);
this.add(getJButton(), null);
this.add(jLabel, null);
this.add(getJTextField(), null);
this.add(getJButton1(), null);
this.add(getJTextField1(), null);
this.add(jLabel1, null);
this.add(jLabel11, null);
this.add(jLabel111, null);
this.add(jLabel112, null);
this.add(jLabel113, null);
this.add(getJTextField11(), null);
this.add(jLabel114, null);
this.add(getJTextField111(), null);
this.add(getJTextField1111(), null);
this.add(getJTextField2(), null);
this.add(getJTextField3(), null);
this.add(getJTextField4(), null);
this.add(jLabel2, null);
this.add(jLabel3, null);
this.add(getJButton11(), null);
this.add(getJButton111(), null);
}
} // @jve:decl-index=0:visual-constraint="30,21"
por favor, se alguem souber o que tem de errado, da uma força pra mim.
Valew