Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 86,392 Java Programmers. There are 1,403 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Java Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

the method openFName() from the type WordPadOpen is not static

 
Reply to this topicStart new topic

the method openFName() from the type WordPadOpen is not static

emily327
post 9 May, 2008 - 07:42 AM
Post #1


New D.I.C Head

*
Joined: 9 May, 2008
Posts: 2



The WordPadOpen class creates a file name based on the calling script, then opens a WordPad document under that name. The callWordPadOpen class is a test of how the first would be instantiated in a number of other scripts (all separate files). I keep getting an error on the line "String opened = WordPadOpen.openFName();" (in the callWordPad class) that says "method openFName() from the type WordPadOpen is not static." But I can't see any reason why it would need to be, and if I make it, then all the calls inside it to things like "documentWordPadwindow" and "comboBox" complain that they need to be static, but they are from a recorded script that is not supposed to be changed. How do I fix it?

CODE

package Components;

import resources.Components.WordPadOpenHelper;
import java.util.*;//for GregorianCalendar
import java.text.*;//for GregorianCalendar
// @author Steve

public class WordPadOpen extends WordPadOpenHelper
{
    Date today;
    String result;
    SimpleDateFormat formatter;

    public void testMain(Object[] args)
    {
        try
        {
            openFName();
        }// end try
        catch (Exception e)
        {
            logError("Exception thrown from WordPadOpen.class");
        }// end catch
    }// end testMain
    
    public String openFName()
    {
        
            Locale oToday = null;
            boolean bExist = true;
            boolean bWPExists = true;
            Date today;
            String result;
            SimpleDateFormat formatter;
            
/* Blocked out by Emily 5/8/08 - next block of code performs similarly            
            for (int i = 0; i < args.length; ++i)
            {
                System.out.println( " arg["+i+"] = "+args[i]);
            }
            System.out.println(args[0]);
            System.out.println("Passed data array is "+args[0]);        
*/    
            
            String[] fName = new String[2];
             fName[0] = getTopScriptName();
             fName[1] = Integer.toString(getTopScriptLineNumber());
             for (int i = 0; i < fName.length; i++)  {
                 System.out.println(fName[i]);
             }
             logInfo(fName[0]);
             
            do
            {    
                bWPExists = documentWordPadwindow().exists();
                if (bWPExists == true)
                {
                    logInfo("Closed open WordPads");
                    callScript("WordPadClose");
                }// end if
                else
                {
                    bWPExists = false;
                    //logInfo("Did not detect macro pop-up");    
                }// end else
            }// end do
            while(bWPExists == true);// end do while    
            
               shellExecute("wordpad.exe");
            sleep(1);
            //tFrame().inputKeys("%{PRTSC}");
            //documentWordPadwindow(ANY,MAY_EXIT).inputKeys("^v");
            documentWordPadwindow(ANY,MAY_EXIT).inputKeys("^s");
        
            oToday = new Locale("en", "US");
            formatter = new SimpleDateFormat("yyyy.MMM.dd.kk.mm", oToday);//, currentLocale // EEE d MMM yy
            today = new Date();
            result = formatter.format(today);
        
            //System.out.println("Locale: " + oToday.toString());
            //System.out.println("Result: " + result);
            //logInfo("Locale: " + oToday.toString());
            logInfo("Result: " + result);         //}
            
            //        logInfo("Script name is " + sTSN +" from line number " + iSLN);
            //        saveAswindow().inputChars(iSLN + sTSN +" "+ result +".rtf");
            logInfo("Script name is "+fName[0]+" from line number "+fName[1]);
            //saveAswindow().inputChars(fName[0]+" "+" "+result+".rtf");
            saveAswindow().inputChars(fName[0]+" "+" "+result+".doc");
    
            desktopbutton().click(atPoint(32,56));
            
        
        // Window: wordpad.exe: Save As
        comboBoxcomboBox2().click(ARROW);
        comboBoxcomboBox2().click(atPoint(185,7));
        saveAswindow().inputChars(".");
        savebutton().click(atPoint(39,16));    
        return fName[0];
        
        
    }// end openFName
}// end class WordPadOpen



package Components;

import resources.Components.callWordPadOpenHelper;
import Components.WordPadOpen;

public class callWordPadOpen extends callWordPadOpenHelper
{
    public void testMain(Object[] args)
    {
        String opened = WordPadOpen.openFName();
        System.out.println("Opened the file " + opened);
        logInfo("Opened file " + opened);
    }
}// end class callWordPadOpen
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


pbl
post 9 May, 2008 - 08:50 AM
Post #2


D.I.C Addict

Group Icon
Joined: 6 Mar, 2008
Posts: 849

CODE

public class callWordPadOpenHelper
{
    public void testMain(Object[] args)
    {
        String opened = WordPadOpen.openFName();
        System.out.println("Opened the file " + opened);
        logInfo("Opened file " + opened);
    }
}// end


The method openFName() is not static. It has to be static if you want to call that way

CODE

        String opened = WordPadOpen.openFName();


But this probably not what you want to do.
You have to create first an Object of type WordPadOpen and then you can call the instance of openFName() of that object

CODE

   WordPabOpen wpo = new WordPadOpen();
   String opened = wpo.openFName();


User is offlineProfile CardPM
Go to the top of the page
+Quote Post

emily327
post 10 May, 2008 - 10:15 AM
Post #3


New D.I.C Head

*
Joined: 9 May, 2008
Posts: 2

I tried something very similar to that, and it was still throwing the error, but perhaps I made a mistake. I will try that when I get back to work on Monday. Thanks!

This post has been edited by emily327: 10 May, 2008 - 10:19 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 05:08AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month