我遇到以下错误,请在我做错地方帮助我
ERROR n.s.wurfl.core.GeneralWURFLEngine - cannot initialize: java.lang.NullPointerException: in is null
java.lang.NullPointerException: in is null
at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:100) ~[na:1.7.0_72]
at java.util.zip.ZipInputStream.<init>(ZipInputStream.java:79) ~[na:1.7.0_72]
at net.sourceforge.wurfl.core.resource.FileLoader.fromZipFile(FileLoader.java:248) ~[wurfl-1.5.jar:na]
at net.sourceforge.wurfl.core.resource.FileLoader.openInputStream(FileLoader.java:230) ~[wurfl-1.5.jar:na]
wurfl.zip位于/ web-inf /中,而我的wurfl弹簧配置如下
<bean id="net.sourceforge.wurfl.core.WURFLEngine" class="net.sourceforge.wurfl.core.GeneralWURFLEngine">
<constructor-arg index="0" value="classpath:/wurfl.zip" />
<property name="engineTarget" value="performance" />
上面实现的代码是
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
WURFLEngine holder = (WURFLEngine)wac.getBean(WURFLEngine.class.getName());
System.out.println("debugging request: "+request+" ==wurflholder: "+holder+ " Holder String "+holder.toString());
显示的输出:
debugging request: org.apache.catalina.core.ApplicationHttpRequest@133b7e9
==wurflholder: net.sourceforge.wurfl.core.GeneralWURFLEngine@6f28c4
==Holder: String net.sourceforge.wurfl.core.GeneralWURFLEngine@6f28c4
但是它在以下代码上给出了错误
try{
device = holder.getDeviceForRequest(request); //This is giving exception
}
catch(Exception e ){e.printStackTrace();}
请指教。
最佳答案
/web-inf/
目录不在类路径中,这将导致引发异常。
尝试将wurfl.zip
放在/web-inf/classes
中,以使其正确加载。