I'm stuck in service loader class(java) can anybody help, here is my code and pic attached with it. see the pic to understand completely and tell me what's the issue
Interface Code
package ServiceLoader_.SL;
interface Account {
String getMessage();
}
Class implementing that interface
package ServiceLoader_.SL;
public class Message implements Account {
@Override
public String getMessage() {
return "Hello";
}
}
Main class
package ServiceLoader_.SL;
import java.util.ServiceLoader;
public class main {
public static void main(String[] args) {
ServiceLoader<Account> ac = ServiceLoader.load(Account.class);
Account ab = ac.iterator().next();
if(ac.iterator().hasNext()){
System.out.println("hay^");
}
}
}
Gives error that no such element found when trying to access ac.iterator().next()
Click HereTo See Image