Subj : Re: NullPointerException To : Arumugam Appadurai From : Igor Bukanov Date : Wed May 28 2003 03:38 pm Arumugam Appadurai wrote: > I am using Jdk1.4.1 > The following is the one that I am doing exactly, > > private Context mCtx = null; > private Scriptable mScope = null; > ResourceWriter resWr = null; > > mCtx = Context.enter(); > resWr = new ResourceWriter(new PrintWriter(System.out)); > mScope = mCtx.initStandardObjects(null); > Scriptable jsArgs = Context.toObject(resWr,mScope); > mScope.put("out", mScope, jsArgs); > mCtx.evaluateString(mScope, jsContent, mScope.getClassName(), 1, null); You should replace this by: private Scriptable mScope = null; ResourceWriter resWr = null; ... Context cx = Context.enter(); try { resWr = new ResourceWriter(new PrintWriter(System.out)); mScope = cx.initStandardObjects(null); Scriptable jsArgs = Context.toObject(resWr,mScope); mScope.put("out", mScope, jsArgs); cx.evaluateString(mScope, jsContent, mScope.getClassName(), 1, null); } finally { Context.exit(); } You should always use this Context.enter()/exit() pattern and never cache Contex object. A simple way to ensure it is never store Context instances in class fields. Regards, Igor .