여기Singleton
에서 SQLiteOpenHelper
같은 것을 인스턴스화 하기 위해 사용 하고 싶습니다 .
이 코드를 SQLiteOpenHelper 클래스에 넣어 보았습니다.
public static synchronized DatabaseHelper getInstance(Context context) {
if (sInstance == null) {
sInstance = new DatabaseHelper(context.getApplicationContext());
}
return sInstance;
}
하지만 다음과 같이 내 저장소 클래스에서 해당 메서드를 호출하려고 할 때 :
public UserAccountRepository(Context context) {
super(context);
dbHelper = new DatabaseHelper.getInstance(context);
}
android studio에 오류가 표시됩니다.
기호 getinstance를 확인할 수 없습니다.
new
새 개체를 만들고 생성자라고 부르는 데 사용됩니다.
이것은 실제로하고 싶은 것이 아닙니다 (이미에서 수행 한 작업입니다 getInstance
). 반환 값 getInstace
을 일부 지역 변수 에 할당하고 싶습니다 . 그냥 버려 new
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다