• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

null object reference when using registering user on Android Studio

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm learning by building an app in Android Studio. I have a MYSQL server running on a linux VM. I'm trying to test registering a 'user', but I'm receiving the following error:

I/System.out: ERROR WHEN CREATING USER: Attempt to invoke interface method 'java.sql.ResultSet java.sql.Statement.executeQuery(java.lang.String)' on a null object reference
W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.ResultSet java.sql.Statement.executeQuery(java.lang.String)' on a null object reference
       at Database2.register(Database2.java:45)
       at Register$1.onClick(Register.java:41)
       at android.view.View.performClick(View.java:7125)
       at android.view.View.performClickInternal(View.java:7102)
       at android.view.View.access$3500(View.java:801)
       at android.view.View$PerformClick.run(View.java:27336)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)


Database class

Register class


Some things I have checked and believe are true:
The port is indeed 3306.
The IP is correct and so is the URL.

Any guidance is appreciated, thank you.

 
Rancher
Posts: 449
7
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried just run Database2 ? Did it prints "DATABASE CONNECTION WAS SUCCESSFUL" ?
 
Rancher
Posts: 4492
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
statment is only initialised in the main mehtod of Database2.
I don't see anywhere where that method is called in your code, so statement is always null.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!