私はメインメソッドで持っているクラスのオブジェクトを作成しようとしていますが、私はレイジーシンプトンパターンを実装していますが、エラーがクラス内でシンボルを見つけることができません。私はインポートパッケージ文を正しく書いたかどうかを調べました。メソッドが既に宣言されている場合、クラスでメソッドが見つかりませんか?
これは私がメインクラスでApplicationModelを入力するたびに、import文のエラーは輸入がされていないことを示す。これは私のシングルトンクラスApplicationModelある
package control;
import java.io.File;
import java.io.FileNotFoundException;
import model.ApplicationModel;
import java.util.* ;
import model.Shop;
import view.ApplicationViewer;
import model.ApplicationModel;
public class ApplicationControl {
public static void main (String[] args) throws FileNotFoundException{
ApplicationModel apm = new ApplicationModel.getInstance();
}
}
package model;
// needed for ArrayLists
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ApplicationModel {
private static ApplicationModel instance = null;
private ApplicationModel()
{
}
public static ApplicationModel getInstance(){
if (instance == null){
instance = new ApplicationModel();
}
return instance;
}
private List<Shop> shops = new ArrayList<Shop>();
public List<Shop> getShops(){
return this.shops;
}
public void setShops(List<Shop> shops){
this.shops = shops;
}
public Shop createShop(String csvString){
String[] attributes = csvString.split(",");
Shop shop = new Shop(attributes[0],attributes[1],attributes[2],
attributes[3],attributes[4]);
return shop;
}
public List<Shop> readShops(String shopFileName){
ApplicationModel am = new ApplicationModel();
List<Shop> shopList = new ArrayList<>();
try{
Scanner naughty = new Scanner(new File(shopFileName));
if (naughty.hasNext()) naughty.nextLine();
while(naughty.hasNext()){
shopList.add(am.createShop(naughty.nextLine()));
}
} catch (FileNotFoundException ex) {
Logger.getLogger(ApplicationModel.class.getName()).log(Level.SEVERE, null, ex);
}
return shopList;
}
public String printShops(){
String listOfShops ="";
for(Shop shop : shops){
listOfShops = listOfShops +'\n'+ shop.toString().trim() + '\n';
}
return listOfShops.trim();
}
}
私のメインクラスです使われなくなっても、何が間違っているのか分かりません(私はネットビーンズを使っています)。誰も助けることができますか?あなたのコードから
ここで、あなたのクラスのヘッダは 'class ApplicationModel {..}'を意味しますか? –
'ApplicationModel apm = new ApplicationModel.getInstance();' newは何をすべきか? – tkausl
@tkauslシングルトンクラスの新しいインスタンスを作成しませんか?私が作成した新しいオブジェクトです。 –