0

I am new to java.I created a JFrame class in netbeans, then i did

public class Tela extends javax.swing.JFrame{
...
public Tela(){
Status st;   
lblCarism.setText("Carisma: "+st.getCarism());
             }
}

Then I have the Class Jogo:

public class Jogo{
    static Status st;

public static void main(String[] args){
    int[] vida = {12,12};
    st = new Status("Diegolo","todos","Libertado","espirito",vida,8,4,2,2,8,0,7,5,20,13,16,0,40,1,0);
    Tela.start();
}

}

And The class Status

public class Status {

String nome;
String Sex;
String Classe;
String Raca;
int[] Vida = new int[2];
int forca;
int vel;
int pontoVel;
int percep;
int furt;
int impac;
int mira;
int intel;
int carism;
int defCort;
int defPerf;
int defMag;
int Xp;
int lvl;
int ouro;
int poder;

public Status(String nom, String Sex, String Classe, String Raca, int vida[], int forca, int vel, int percep, int furt, int impac, int mira, int intel, int carism, int defCort, int defPerf, int defMag, int poder, int Xp, int lvl, int ouro) {

    pontoVel = (int) vel / 10;
    this.nome = nom;
    this.Sex = Sex;
    this.Classe = Classe;
    this.Raca = Raca;
    for (int i = 0; i <= 1;i++) {
        this.Vida[i] = vida[i];
    }
    this.forca = forca;
    this.vel = vel;
    this.percep = percep;
    this.furt = furt;
    this.impac = impac;
    this.mira = mira;
    this.intel = intel;
    this.carism = carism;
    this.defCort = defCort;
    this.defMag = defMag;
    this.defPerf = defPerf;
    this.Xp = Xp;
    this.lvl = lvl;
    this.ouro = ouro;
    this.poder = poder;
}
//getters and setters
}

The Problem is, when i compile the code, it returns a Null exception because of the

lblCarism.setText("Carisma: "+st.getCarism());

line, but I ititialized the Carism already.Is there a way to tell the Jframe class that i updated the Carisma?(I didn't find anything about it on internet)

Edit:Even if i try lblCarism.setText("Carisma: "+Jogo.st.getCarism()); it returns Null Exception, and this question isn't a duplicate.I'm asking about swing and not about Null Exceptions.

Diegovsky
  • 13
  • 5
  • You never assigned `Jogo.st` to `Tela.st` - I really think you need to take some time and read through [Passing Information to a Method or a Constructor](https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html) – MadProgrammer Jul 06 '17 at 02:02
  • `st` looks to be uninitialized – Hovercraft Full Of Eels Jul 06 '17 at 02:02
  • `public Tela(){ Status st; ` - yep the value of `st` is null, so you can not do `lblCarism.setText("Carisma: "+st.getCarism());` – Scary Wombat Jul 06 '17 at 02:02
  • That you're asking this sort of question in reference to a Swing application suggests that you may be putting the "cart before the horse", that is trying to learn a complex corner of Java, here multi-class Swing GUI programming, before learning the basics of Java and how to do object oriented programming with Java. Start at the beginning and learn the fundamentals first and you will avoid a host of frustrations. – Hovercraft Full Of Eels Jul 06 '17 at 02:07
  • Thank you!I really appreciate your help – Diegovsky Jul 08 '17 at 01:17

0 Answers0