?
Solved

How to avoid this messsage (Static Issues)

Posted on 2004-08-17
5
Medium Priority
?
367 Views
Last Modified: 2010-03-31
This is my code:

program A:
========
...
...
public static synchronized Date getToday()
  {      
        return new Date();
   }
..
..


trying to access from here..

Program B:
=======
...
...
piObj.getContmstr().setInituwrtdt(new DateUtil().getToday());
...
...


And my "warning" message is this :

The static method getToday() from the type DateUtil should be accessed in a static way.


Question
=====
How can i resovel this issues?

ThankYou.



0
Comment
Question by:acl6804
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:pat5star
ID: 11827486
I'm assuming program A is a class called DateUtil. If so, you can call it like this:

piObj.getContmstr().setInituwrtdt(DateUtil.getToday());

You do not need to use the 'new' keyword when calling a static method. You just use the class name and the method you are calling.

Hope that helps,

-Pat
0
 

Author Comment

by:acl6804
ID: 11828579
but if i remove the "new" in the line, i will haev this problem.

"The method DateUtil() is undefined for the type PropInputServlet

** PropInputServlet is the name of my program B.

0
 
LVL 3

Accepted Solution

by:
pat5star earned 1000 total points
ID: 11828911
Make sure your not writing it as DateUtil().getToday(), it should be DateUtil.getToday(). Also, are you importing your 2nd class? If the class is called DateUtil and is in your package my.package.DateUtil then you need to import it at the top of your page like this:

import my.package.DateUtil;

-Pat
0
 

Author Comment

by:acl6804
ID: 11837851
oh.. no wonder.. pat5star, can tell me what happend?

static means no need "new"??
0
 
LVL 3

Expert Comment

by:pat5star
ID: 11838127
"static means no need "new"??"

Your right. Static methods or fields are like global variables or functions. You only use the "new" keyword when you are creating a new object.

-Pat
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question