Witam
Jest taki kod:
import java.util.*;
/**
* Write a description of class Party here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Party
{
public ArrayList<String> listName = new ArrayList<String>();
public ArrayList<String> listSec = new ArrayList<String>();
/**
* Constructor for objects of class Party
*/
public Party()
{
//listName = new ArrayList<String>();
//listSec = new ArrayList<String>();
guestList();
secureGuestList(listName);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public ArrayList guestList()
{
listName.add("alan");
listName.add("bree");
listName.add("lord copper");
listName.add("dan");
listName.add("lady elizabeth");
listName.add("freda");
listName.add("gary");
return listName;
}
public ArrayList secureGuestList(ArrayList List)
{
List = guestList();
int listSize=listName.size();
int i;
String security="security guard";
for (i=0;i<listSize;i++)
{
String listElement = listName.get(i);
if (listElement.substring(0,4)=="lord")
{
listElement=listElement+security + listElement;
}
if (listElement.substring(0,4)=="lady")
{
listElement=listElement+security + listElement;
}
else
{
listSec.add(listElement);
}
}
return listSec;
}
}
Problem w tym, że po poprawnym skompilowaniu (w środowisku BlueJ), przy próbie wywołania poprzez:
Party.secureGuestList(Party.guestList());
Wyskakuje mi błąd "Semantic error: Cannot reach instance method: guestList() from static context: Party"...
Możecie mnie naprowadzić, gdzie jest błąd?
Z góry dzięki...
Cytat: krzyszp w 30 Kwiecień 2008, 20:41
Problem w tym, że po poprawnym skompilowaniu (w środowisku BlueJ), przy próbie wywołania poprzez:
Party.secureGuestList(Party.guestList());
Wyskakuje mi błąd "Semantic error: Cannot reach instance method: guestList() from static context: Party"...
Na mój nos w swoim kodzie zamiast do instancji obiektu klasy Party odwołujesz się bezpośrednio do metody guestList() tej klasy (Tak mógłbyś tylko gdyby była to metoda statyczna!).
Cytat: Ivul Divul w 05 Maj 2008, 11:26
Na mój nos w swoim kodzie zamiast do instancji obiektu klasy Party odwołujesz się bezpośrednio do metody guestList() tej klasy (Tak mógłbyś tylko gdyby była to metoda statyczna!).
True, true. ;)