Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to avoid this messsage (Static Issues)

Posted on 2004-08-17
5
Medium Priority
?
373 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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

636 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