我使用wurfl来检测移动设备。 我初始化GeneralWURFLEngine但它无法初始化
我的代码:
public static final String path = "wurfl.zip";
private static ThreadLocal<WURFLEngine> wulEngine = new ThreadLocal<WURFLEngine>() {
protected WURFLEngine initialValue() {
return new GeneralWURFLEngine(path);
};
};
Device device = wulEngine.get()
.getDeviceForRequest(userAgentString);
错误:
ERROR core.GeneralWURFLEngine (GeneralWURFLEngine.java:274) - cannot initialize: net.sourceforge.wurfl.core.resource.exc.WURFLResourceException: WURFL unexpected exception
net.sourceforge.wurfl.core.resource.exc.WURFLResourceException: WURFL unexpected exception
at net.sourceforge.wurfl.core.resource.XMLResource.readData(XMLResource.java:350)
at net.sourceforge.wurfl.core.resource.XMLResource.getData(XMLResource.java:154)
at net.sourceforge.wurfl.core.resource.DefaultWURFLModel.init(DefaultWURFLModel.java:118)
at net.sourceforge.wurfl.core.resource.DefaultWURFLModel.<init>(DefaultWURFLModel.java:110)
at net.sourceforge.wurfl.core.GeneralWURFLEngine.init(GeneralWURFLEngine.java:293)
at net.sourceforge.wurfl.core.GeneralWURFLEngine.initIfNeeded(GeneralWURFLEngine.java:272)
at net.sourceforge.wurfl.core.GeneralWURFLEngine.getDeviceForRequest(GeneralWURFLEngine.java:41
我该如何修复bug?谢谢你的帮助
答案 0 :(得分:3)
这是一个初始化GeneralWURFLEngine
的工作示例import net.sourceforge.wurfl.core.Device;
import net.sourceforge.wurfl.core.EngineTarget;
import net.sourceforge.wurfl.core.GeneralWURFLEngine;
public static void main(String[] args) {
GeneralWURFLEngine wurfl = new GeneralWURFLEngine("wurfl.zip");
wurfl.setEngineTarget(EngineTarget.performance);
Device device = wurfl.getDeviceForRequest("User-Agent/5 FooBar");
System.out.println(device.getCapability('model_name'));
}