4
I need to pass variable data to another class called Fila.java. There I have a vector of the type that receives objects, so in the main class I created an object that I initialized as follows :
public class Dados{
int menu = 20,i=0;
String produto;
int Quantidade=0;
float ValorUn=0,Desconto=0,AliquotaICMS=0;
String Obs;
}
public static void main(String[] args) {
BancoDeDados db = null;
Dados da = new Dados;
da.menu = 20;
}
However intendente the way I initialize it, generates error when compiling
If I start like this :
Dados da;
It says that the variable was not initialized, if I assign the value NULL, says it’s pointing to a null pointer, how to solve?
Classe Fila.java
public class Fila {
public Fila() {
}
int inicio, fim, numelem,tamanho;
Object array[];
String elem;//string
Fila(int tam){
this.inicio = 0;
this.fim = 0;
this.numelem = 0;
this.tamanho=tam;
this.array = new Object[tam];
}
public boolean vazia(){
if(numelem==0)
return true;
return false;
}
public void inserir(Object elem){
array[fim]=elem;
numelem++;
fim++;
if(fim==tamanho)
fim=0;
System.out.println(array[0]);
}
public Object remover(){
Object temp=null;
if(!vazia()){
temp=array[inicio];
array[inicio]=null;
inicio++;
numelem--;
if(inicio==tamanho)
inicio=0;
}
else
System.out.println("Fila vazia");
return temp;
}
public void AumentarVetor() {
tamanho = (tamanho/2)*3;
}
}
Main class :
import BancoDeDados.Dados;
public class Main {
public static class Dados{
int menu = 20,i=0;
String produto;
int Quantidade=0;
float ValorUn=0,Desconto=0,AliquotaICMS=0;
String Obs;
public Dados(){
//também á uma boa idéia inicializar os valores das variáveis dentro do construtor
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//BancoDeDados db = null;
//BancoDeDados.main(args);
Dados da = new Dados();
da.menu = 20;
da.produto = "Teste";
Fila f = new Fila();
da.menu = 10;
f.inserir(da);
}
}
You should describe the error obtained when compiling. Note that apparently your code is wrong. The most method is outside the class. Apparently scattered in the archive.
– josivan
Good evening, It shows following message : "The local variable da may not have been initialized. " But I don’t know how I should boot it.
– Viniciusmvaj