So i don\'t know what the rules are here about double posts, anywho i didn\'t get follow up support on my other question.. anywho my problem is stated, heres my logcat
Check your logs
you have a NullPointerException in the line
xela.kasea.flyffresell.Main.onCreate(Main.java:31)
May be one of the buttons clear, submit, ret, lazy
might be null
.
I think this comment from the user requires an answer that explains the fundamental topic of what null
is in Java:
if i may ask, whats a NullPointerException?
null
pointer means that you are trying to manipulate an Object
variable that does not have any memory allocated to it. The NullPointerException
is Java's way of telling you: "Hey, the variable that you are trying to manipulate (i.e. set a listener to) is pointing to no memory location; there was no Object
instantiated for this variable or it was already garbage collected. You are trying to go to use the bathroom of a building that hasn't been built yet."
The stacktrace is nice (you should be friends with him) and tells us in which line of our code the Exception
is thrown:
05-28 19:45:04.425: E/AndroidRuntime(793): Caused by: java.lang.NullPointerException
05-28 19:45:04.425: E/AndroidRuntime(793): at xela.kasea.flyffresell.Main.onCreate(Main.java:31)
This means that you need to go and check that line of code and figure out which variable is null
. Most modern IDE's have the option of introducing breakpoints that allow you to see a variable's state at runtime. Once you know which variable is null
you can more easily figure out why. So in your case, the line causing problems is line 31 of Main.java
. From the comments we know you said that line is:
ret.setOnClickListender(this);
That leave us with one option; ret
has to be null
. Then we ask ourselves:
What can happen, under normal conditions, that can make ret be
null
?
1) The variable is not initialized; we forgot to initialize it. Not our case.
2) The variable was garbaged collected. Not our case.
3) Something went wrong when we tried to initialize our variable. Probably our case.
In this case, we do not initialize the variable by calling the constructor of some class, we do it via a method (i.e. findViewById()
). This method takes an int
that should be the id
of the View
we want to set ret
to, and it either returns null
or the View
in question. So, if thought this out correctly, the error probably is that we used the wrong id.
This answer is more to show a thinking pattern rather than an actual solution since there really is not enough information to solve the problem.
According to your error message:
05-28 19:45:04.425: E/AndroidRuntime(793): Caused by: java.lang.NullPointerException
05-28 19:45:04.425: E/AndroidRuntime(793): at xela.kasea.flyffresell.Main.onCreate(Main.java:31)
the problem must be the button "bReturn
" inside your layout
ret = (Button) findViewById(R.id.bReturn);
probably doesn´t exist.
Update: well i found the problem, why load the contentview again when you click the bReturn button?:
case R.id.bReturn:
setContentView(R.layout.display);