Don't initialize GeneralWURFLEngine

503 Views Asked by At

I used wurfl for detecting devices on mobile. I initialize GeneralWURFLEngine but it cannot initialize

My code:

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:

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

how can i fix bug? thank you for your help

1

There are 1 best solutions below

0
Elliot Fehr On BEST ANSWER

Here is a working example to initialize the 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'));
}