aspose file tools*
The moose likes Beginning Java and the fly likes Calling a static method from main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling a static method from main()" Watch "Calling a static method from main()" New topic
Author

Calling a static method from main()

Banah Vor
Greenhorn

Joined: Jan 03, 2011
Posts: 1

Hi all,

I am trying to call a method from the main() but encountered NullPointerException once it tries to call. The code is something like this.



I'm fairly new in java and your assistance will be valued.


Bana
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Please PostRealCode and also the stacktrace so that we can get to know what the code is trying to do.


Mohamed Sanaulla | My Blog
Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 61

Mohamed Sanaulla wrote:Please PostRealCode and also the stacktrace so that we can get to know what the code is trying to do.


yup...
The snippet you've posted doesn't show anything as to what is null there...
Need the actual code here


SCJP-6.0 OCPJWCD-5.0
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14274
    
  21

Welcome to JavaRanch.

NullPointerExceptions are most of the time easy to track down and fix. Look at the stack trace that you get from the exception. It tells you exactly in which source file, and which line of code, the exception happens. Go to that spot in your source code and find out what could be null there that is not supposed to be null.

The most common causes of a NullPointerException are trying to call a method on a variable that is null or trying to access a member variable while the variable that refers to the object is null.

The outline of your code that you posted doesn't give enough information to help you with this problem.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Welcome to the Ranch

As you have already been told, it is impossible to help with your problem unless we know more details.
 
 
subject: Calling a static method from main()