[英]Java - No enclosing instance of the type … is accessible in scope
我有這個課:
public class PetAssembly extends Global
{
public Socket socket;
public ConnectionManager user;
public PetAssembly(Socket socket, ConnectionManager user)
{
this.socket = socket;
this.user = user;
}
public void initPet()
{
sendPacket(socket, "0|PET|I|0|0|1");
sendPacket(socket, "0|PET|S|1000|1|0|8000|50000|50000|1000|1000|50000|50000|" + (((user.user.getSpeed() * 30) / 100) + user.user.getSpeed()) + "|testPet");
}
}
我要使用它:
case "/pet":
PetAssembly.this.initPet();
break;
但這給了我這個錯誤,如何解決? 我是一個初學者:作用No enclosing instance of the type PetAssembly is accessible in scope
PetAssembly.initPet()是一個實例方法。 您首先需要構造一個PetAssembly對象(該類的實例),然后對該對象進行引用,然后才能在該對象上調用方法。
PetAssembly pa = new PetAssembly(socket, user);
// Creates a new PetAssembly object
// and stores a reference to that in the variable pa.
pa.initPet();
// Calls the initPet() method on the PetAssembly object referred to by the variable pa.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.