我做了一個類,它返回一個ArrayList的3個值給主程序,但是當我使用我的get()
方法時,編譯器會拋出錯誤,找不到這個方法 - 符號。我嘗試了同樣的事情,而不是一個數組,而是一個數組,它似乎工作。但我不能用數組列表的方式來確定它的方式。從Arraylist的類上獲取方法
//錯誤顯示第二個代碼標記上的「action evt」顯示按鈕。
錯誤信息是:「無法找到符號方法getmarka()」。
我在下面的代碼發佈也許你可以幫我。
與返回值GET方法的類:
public class Cars
{
private String modelo,marka;
private int kyvismos;
public Cars(String m,String ma,int k)
{
modelo=m;
marka=ma;
kyvismos=k;
}
public String getmodelo()
{
return modelo;
}
public String getmarka()
{
return marka;
}
public int getkyvismos()
{
return kyvismos;
}
public void setmodelo(String m)
{
modelo=m;
}
public void setmarka(String ma)
{
marka=ma;
}
public void setkyvismos(int k)
{
kyvismos=k;
}
public String toString()
{
return modelo+","+marka+","+kyvismos;
}
}
這裏是獲取在頂部的類級類。
public class MyFrame extends Frame
{
ArrayList<Cars> Cars = new ArrayList<>();
private Button add;
private Button show;
private Button quit;
public MyFrame(String title)
{
super(title);
resize(500,300);
setResizable(false);
setLayout(new GridLayout(3,1));
add=new Button("ADD");
show=new Button("SHOW");
quit=new Button("QUIT");
add (add);
add (show);
add (quit);
}
public boolean action(Event evt,Object arg)
{
if(evt.target.equals(add))
{
String value1= JOptionPane.showInputDialog("Enter Car Model ");
String value2= JOptionPane.showInputDialog("Enter Car Mark ");
int value3= Integer.parseInt(JOptionPane.showInputDialog("Enter Kyvismos "));
Integer I=new Integer(value3);
Cars.add(new Cars(value1,value2,value3));//or pinakas.add(value);
}
else
if(evt.target.equals(show))
{
String s="";
int i;
for(i=0;i<Cars.size();i++){
**//here is the error on Cars.getkyvismos() or getmarka() or getmodelo();**
//if(Cars.getkyvismos()>1900)
s=s+Cars.getmarka()+Cars.getmodelo()+"\n";
}
JOptionPane.showMessageDialog(null, "cars with kyvismo >1900 are \n " + s);
}
else
if(evt.target.equals(quit))
{
System.exit(0);
}
return true;
}
}
在此先感謝和抱歉,如果它是一個新手的問題!
的可能的複製[什麼是一個「無法找到符號」編譯錯誤是什麼意思?(http://stackoverflow.com/questions/25706216/what-does-a- can not-find-symbol-compilation-error-mean) – azurefrog
請使用** exact **錯誤信息編輯您的問題。 –
@ Code-Apprentice錯誤信息是:「找不到符號方法getmarka()」。 – foutzos