Alireza Azadi wrote:I use jTDS 1.3.0.
In MainActivity i create new instance of my ConnectionHelper class and give return connection to a CallableStatement.
It gives me RunTimeException ( I think because i call it in onCreate method of MainActivity) and NullPointException in the line :
Roel De Nijs wrote:
Alireza Azadi wrote:I use jTDS 1.3.0.
In MainActivity i create new instance of my ConnectionHelper class and give return connection to a CallableStatement.
It gives me RunTimeException ( I think because i call it in onCreate method of MainActivity) and NullPointException in the line :
You think you get a runtime exception Could you share the stack trace of the exception?
Roel De Nijs wrote:And what's conn? And what's getMyConnection returning?
Dave Tolls wrote:Where in that code are you actually setting the connection attribute?
It's not happening in your constructor.
Alireza Azadi wrote:Here is my ConnectionHelper class that conn is an instance of it :
Dave Tolls wrote:Where in that code are you actually setting the connection attribute?
It's not happening in your constructor.
Roel De Nijs wrote:
Alireza Azadi wrote:Here is my ConnectionHelper class that conn is an instance of it :
And is connection actually initialized or does the try-block throws some exception?
What's the output if you add this statement as the final line of the ConnectionHelper constructor?
Roel De Nijs wrote:
Alireza Azadi wrote:Here is my ConnectionHelper class that conn is an instance of it :
And is connection actually initialized or does the try-block throws some exception?
What's the output if you add this statement as the final line of the ConnectionHelper constructor?
Alireza Azadi wrote:The method returns nothing.
Alireza Azadi wrote:And in debug mode when i create a break point at line debugger says conn is null !
Roel De Nijs wrote:
Dave Tolls wrote:Where in that code are you actually setting the connection attribute?
It's not happening in your constructor.
I believe the connection is set using this line of code in the constructor
Roel De Nijs wrote:
Alireza Azadi wrote:The method returns nothing.
I'm not familiar with Android development, so no idea how you can easily add a few log statements. Let me ask another question: if you add that line to the constructor and you put a breakpoint on that line and start debugging, what's the value of connection? I assume it's null because something went wrong in the try block.
Alireza Azadi wrote:And in debug mode when i create a break point at line debugger says conn is null !
That makes no sense! conn can never be null, because you have created an instance and assigned it to conn on line8
Alireza Azadi wrote:Believe me it returns null.
Roel De Nijs wrote:
Alireza Azadi wrote:Believe me it returns null.
No, I don't believe it! Your conn is a local reference variable (in the onCreate method) which is initialized a few lines before you used it. So conn can never be null!
Now the code that you show, just uses conn but you didn't show any code to create conn (and it can't be the same one as the one in MainActivity because that was a local variable). But I can believe conn.getMyConnection() is returning null, because (as mentioned in several posts) the try-block is throwing some kind of exception (and then the connection field in the ConnectionHelper class is not initialized and thus null). But according to you, there's nothing in the logs. So either you have to debug your application (and especially the try and catch blocks) or change the catch handlers toand then your application will blow up while running and you get the actual root cause of your problem. Because the NullPointerException you are experiencing is probably just a side-effect, it's not the root cause! (unless you are of course invoking setConnection in the ConnectionHelper class with null as parameter somewhere in the code)
Hope it helps!
Kind regards,
Roel
Alireza Azadi wrote:
I solved it !
I finally solved it ! :-D
Why you do not believe me? :-D
It returned null.
Problem was collation.
The collation of SQL Server 2012 i want to connect is Persian_....
Now i changed the Collation to defualt Latin_General_.....
And returns net.sourceforge.....
Thanks all for pay attention.
Alireza Azadi wrote:Why you do not believe me? :-D
It returned null.
So I did believe you! I just didn't believe this part in one of your postsRoel De Nijs wrote:But I can believe conn.getMyConnection() is returning null, because (as mentioned in several posts) the try-block is throwing some kind of exception (and then the connection field in the ConnectionHelper class is not initialized and thus null). But according to you, there's nothing in the logs.
Alireza Azadi wrote:debugger says conn is null !
Alireza Azadi wrote:I solved it !
I finally solved it ! :-D