小编Luc*_*rdt的帖子

应用程序崩溃使用iCloud Key-Value存储写入

每次我尝试使用iCloud键值存储设置密钥值时,我的应用程序崩溃...

我收到此错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason:     '[<NSUbiquitousKeyValueStore 0x13fd5b8a0> setValue:forUndefinedKey:]: this class     is not key value coding-compliant for the key ladies.'
*** First throw call stack:
(0x1842f0f48 0x19979bf80 0x1842f0c08 0x18516c014 0x1000e5380 0x1000e9914     0x1000f0430 0x1000f046c 0x1000f04a0 0x1000f04e4 0x1898bf240 0x1898bed3c     0x1898bebc4 0x189085c2c 0x101429c68 0x10142f710 0x1842a81f8 0x1842a6060 0x1841d4ca0 0x18f758088 0x1898ecffc 0x1000f4564 0x199fde8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
Run Code Online (Sandbox Code Playgroud)

我定义了我的密钥库:

var iCloudStore = NSUbiquitousKeyValueStore.defaultStore()
Run Code Online (Sandbox Code Playgroud)

像这样设置我的价值:

iCloudStore.setValue(experience, forKey: "experience")
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?我是否必须定义该密钥才能工作?我真的不明白我得到的错误......

ios icloud swift

3
推荐指数
1
解决办法
360
查看次数

从java中下载文件下载百分比

我有这个代码用于下载我的文件:

public static void download()
            throws MalformedURLException, IOException
    {
        BufferedInputStream in = null;
        FileOutputStream out = null;
        try
        {
            in = new BufferedInputStream(new URL("https://www.dropbox.com/s/1uff8eeujplz4sf/files.zip?dl=1").openStream());
            out = new FileOutputStream(System.getProperty("user.home") + "/Adasti/files.zip");
            byte data[] = new byte[1024];
            int count;

            while ((count = in.read(data, 0, 1024)) != -1)
            {
                out.write(data, 0, count);
            }
        } catch (MalformedURLException e1)
        {
            e1.printStackTrace();
        } catch (IOException e2)
        {
            e2.printStackTrace();
        } finally
        {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我想打印下载时下载的百分比.这可能与我的方法有关,如果是,我将如何做?

java download

1
推荐指数
1
解决办法
5140
查看次数

Java Scanner类读取一行然后停止

我有一个使用Scanner类的方法的问题.我正在使用Scanner读取我的文本文件,然后将int解析为数组.

public static void readItems() 
{
    try 
    {
        File file = new File(System.getProperty("user.home") + "./SsGame/item.dat");
        Scanner scanner = new Scanner(file);
        int line = 0;
        while (scanner.hasNextLine())
        {
            String text = scanner.nextLine();
            text = text.replaceAll("\\W", "");
            System.out.println(text.trim());
            PlayerInstance.playerItems[line] = Integer.parseInt(text);
            line++;
        }
        scanner.close();
    } catch (FileNotFoundException e) 
    {
        e.printStackTrace();
    } catch (NumberFormatException e2)
    {
        e2.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

继承人item.txt文件:

1
1
2
3
4
Run Code Online (Sandbox Code Playgroud)

我运行代码,我得到以下输出:

1
Run Code Online (Sandbox Code Playgroud)

我尝试过使用scanner.hasNextInt()和scaner.nextInt(); 为此,但它根本不会打印任何东西.

如果我删除了parseInt部分,那么文件将完成读取并且将打印所有数字.有任何想法吗?

抛出异常:

java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
1179
查看次数

如何在iPhone上禁用横向模式但将其保留在iPad上?

我希望能够只在iPhone上使用肖像模式,但iPad上的肖像和风景都可以吗?

我使用的是Swift,而不是Objective-C.

ios swift

0
推荐指数
1
解决办法
1335
查看次数

标签 统计

ios ×2

java ×2

swift ×2

download ×1

icloud ×1