Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Get Class Method Generating NullPointerException

 
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why a class getMethod would generate a NullPointerException even if ItemV8 itemV8 == null.

 
Master Rancher
Posts: 4604
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post a small, complete program that compiles and executes for testing and shows the problem?
I don't see how that code would cause a NPE, unless the value it returned was used as a reference in a compound statement.
 
Marshal
Posts: 3760
536
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you calling the method using an initialized object reference?
 
Marshal
Posts: 74746
336
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That isn't really a class method, but an instance method; you will suffer an exception if whatever you call it on is null.Class method is usually another name for a static method. You probably won't suffer an NPE for a static method not even if it is called on a null reference.
 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why a class getMethod would generate a NullPointerException even if ItemV8 itemV8 == null.

 
Campbell Ritchie
Marshal
Posts: 74746
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Saloon Keeper
Posts: 8943
76
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:Not sure why a class getMethod would generate a NullPointerException even if ItemV8 itemV8 == null.

The code shown would not throw a NullPointerException. We would need to see more of the code and a complete copy of the exception output.
 
reply
    Bookmark Topic Watch Topic
  • New Topic