Solved

How to avoid this messsage (Static Issues)

Posted on 2004-08-17
5
360 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 250 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse buid path vs tomcat lib path 10 46
How do I remove an object from a 3 60
login form jsp example 2 68
program arguments vs VM arguments 4 54
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

738 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