仅在树莓派上出现java.lang.NoSuchMethodError [英] java.lang.NoSuchMethodError on raspberry pi only

查看:107
本文介绍了仅在树莓派上出现java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Eclipse Kepler Service Release2.我的程序在Eclipse中运行时可以正常运行,而当我使用Windows cmd运行.jar时也可以正常运行.但是,将相同的.jar放在树莓派上,会出现以下错误:

I'm running Eclipse Kepler Service Release 2. My program works fine when I run it in Eclipse, and it also works fine when I run the .jar using windows cmd. However, putting that same .jar onto a raspberry pi, I get the following error:

Exception in thread "Thread-1" java.lang.NoSuchMethodError: java.nio.file.Files.readAllLines(Ljava/nio/file/Path;)Ljava/util/List;

有问题的代码是

import java.nio.file.Files;
import java.nio.file.Path;

import dataTypes.Detection;

public final class FileOperations {
// ...
    public static Detection readDetection(Path p) {
        try {
            List<String> lines = Files.readAllLines(p);
// etc ...

我部分地确信问题出在我错误地编译了jar,但是由于我是这种事情的新手,所以我不知道如何检查我是否做对了.有人有什么建议吗?

I'm partially convinced that the problem lies with my having incorrectly compiled the jar, but since I'm a complete novice at this sort of thing I don't know how to check I'm doing it right. Does anyone have any advice?

推荐答案

您正尝试使用

You're trying to use java.nio.file.Files.readAllLines(Path), which was introduced in Java 8. You're not going to be able to use that in Java 7.

选项:

  • 在树莓派上升级到Java 8
  • 请勿使用Java 8指定的任何类/方法.(将Eclipse项目更改为以Java 7 JRE为目标可以强制执行此操作)

碰巧,readAllLines的重载需要一个Path和一个Charset在Java 7,上可用,无论如何还是更好的重载,因此明确说明您要使用哪种编码.因此,将您的代码更改为:

As it happens, the overload of readAllLines which takes a Path and a Charset is available on Java 7, and that's a better overload to use anyway, so that you're explicit about which encoding you want to use. So change your code to:

// Or whichever Charset you really want...
List<String> lines = Files.readAllLines(p, StandardCharsets.UTF_8);

这篇关于仅在树莓派上出现java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆