neo4j Graphawareソリューションの実装に問題があります。以前は、次のようなGraphDatabaseServiceオブジェクトを作成していました。 -@Contextから注入された変数から他の変数を初期化する
public class TimetreeUtil {
public static GraphDatabaseService db;
public static SingleTimeTree st;
public static TimeTreeBackedEvents ttbe;
public static TimeTreeBusinessLogic ttbl;
public static TimedEventsBusinessLogic tebl;
public static List<Event> eventsFetchedFromTimetree;
public TimetreeUtil() {
db = new GraphDatabaseFactory().newEmbeddedDatabase(new File("..."));
st = new SingleTimeTree(db);
ttbl = new TimeTreeBusinessLogic(db);
ttbe = new TimeTreeBackedEvents(st);
tebl = new TimedEventsBusinessLogic(db, ttbe);
}
}
これはうまくいきました。 GraphDatabaseService、SingleTimeTree、TimeTreeBackedEvents、TimeTreeBusinessLogic、TimedEventsBusinessLogicは静的であり、neo4jが必要とするため、それらはすべきです。
しかし、今では私たちのアーキテクチャが変更されていると我々はGraphDatabaseServiceを注入している -
public class TimetreeUtil {
@Context
public GraphDatabaseService db;
public static SingleTimeTree st;
public static TimeTreeBackedEvents ttbe;
public static TimeTreeBusinessLogic ttbl;
public static TimedEventsBusinessLogic tebl;
public static List<Event> eventsFetchedFromTimetree;
public TimetreeUtil() {
st = new SingleTimeTree(db);
ttbl = new TimeTreeBusinessLogic(db);
ttbe = new TimeTreeBackedEvents(st);
tebl = new TimedEventsBusinessLogic(db, ttbe);
}
}
Timetreeはただのオブジェクトを作成しているヘルパークラスを - だから今、クラスがどのように見える
@Context
public GraphDatabaseService db;
TimetreeUtilクラスをTimetreeUtil util = new TimetreeUtil();
で作成し、TimetreeUtilの1つのメソッドを呼び出します。
コンストラクタが呼び出されるまでに、のdbが既に初期化されていると想定していますが、そうではありません。 dbがnullであるため、st = new SingleTimeTree(db);
がNPEを提供しています。
私はどのように会うことができますか?ありがとう。
デシベルが何をするか、初期化されますプロシージャを呼び出すコードは次のように見えますか? –
こんにちは@ChristopheWillemsen、あなたの返信のおかげで!元の投稿を編集して、何が起きているのかをより明確に示しています。ありがとう。 –