Hi,
I'm getting the error msg, "non-static can't be referenced from a static context", on my Readfile... what is the simplest way of fixing it? Thanks.

import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import javax.mail.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;


public class Bulkloademail {

    public static void main(String[] args) 
    {

    try  {
        String strMethod = "sendMail";
        String fileResults = "Results.csv";
            String fileValues = "Values.csv";
            String strSender = "xxx.com";
            String recp[] = new String[1];
        String body; 

            recp[0] = "xxx.com";

            String file[] = new String[2];

            file[0] = "E_WORK_DIST_CRIT_060713_1_Error.csv";
            file[1] = "E_WORK_DIST_CRIT_060713_1.csv";

        String strresult = Readfile("E_WORK_DIST_CRIT_060713_1_Error.csv");
        body = body + strresult;

            String strSubject = "ECHS - Bulkload Reports ";
            String strMessage = body;


        TestMail mail = new TestMail();         
        mail.postMail(recp,strSubject,strMessage,strSender,file);

            }
            catch(Exception e)
            {
        System.out.println("Sendmail exception");   
            }

    }

    public String Readfile(String file)
        {
        String content;
        FileInputStream fis = new FileInputStream(file);
        int x= fis.available();
        byte b[]= new byte[x];
        fis.read(b);
        content = new String(b);
        return content;

        }


}

Make the method static.

How do I do that? As you can tell, I'm very new to Java. Thanks!

public static String Readfile(String file)

or else create an instance of

Bulkloademail class and call the method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.