胶子'缓存'插件导入

时间:2016-11-07 11:58:34

标签: android javafx gluon

我上周开始学习Gluon / javafx app。我正在this网站上重新创建示例,并且在导入缓存插件时遇到The 50 States App问题。

package com.fiftystates;
import com.gluonhq.charm.down.Services;
import com.gluonhq.impl.charm.down.plugins.*;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;

public class USState {

private static final Cache<String, Image> CACHE;

static {
    CACHE = Services.get(CacheService.class)
            .map(cache -> cache.<String, Image>getCache("images"))
            .orElseThrow(() -> new RuntimeException("No CacheService available"));
}

private static final String URL_PATH = "https://upload.wikimedia.org/wikipedia/commons/thumb/";

public static ObservableList<USState> statesList = FXCollections.observableArrayList(
        new USState("Alabama", "AL", "Montgomery", 4833722, 135767, URL_PATH + "5/5c/Flag_of_Alabama.svg/23px-Flag_of_Alabama.svg.png"),
        new USState("Alaska", "AK", "Juneau", 735132, 1723337, URL_PATH + "e/e6/Flag_of_Alaska.svg/21px-Flag_of_Alaska.svg.png"),

);

public static Image getUSFlag() {
    return getImage(URL_PATH + "a/a4/Flag_of_the_United_States.svg/320px-Flag_of_the_United_States.svg.png");
}

public static Image getImage (String image) {
    if (image==null || image.isEmpty()) {
        return null;
    }
    Image cachedImage = cache.get(image);
    if (cachedImage == null) {
        cachedImage = new Image(image, true);
        cache.put(image, cachedImage);
    }
    return cachedImage;
}
}

错误是&#34;无法将缓存解析为类型&#34;。

更新

build.gradle

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
}
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
jcenter()
maven {
    url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}

mainClassName = 'com.fiftystates.FiftyStates'

dependencies {
compile 'com.gluonhq:charm:4.0.1'
}

jfxmobile {
downConfig {
    version = '3.0.0'
    plugins 'display', 'lifecycle', 'statusbar', 'storage', 'cache'
}
android {
    manifest = 'src/android/AndroidManifest.xml'
}
ios {
    infoPList = file('src/ios/Default-Info.plist')
    forceLinkClasses = [
            'com.gluonhq.**.*',
            'javax.annotations.**.*',
            'javax.inject.**.*',
            'javax.json.**.*',
            'org.glassfish.json.**.*'
    ]
}
}

任何帮助?!

0 个答案:

没有答案