- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的 arduino 汽车制作一个远程控制应用程序。所使用的代码首先在 Eclipse 中使用 Java 进行了测试,现在我正在尝试将相同的代码用于 Android 应用程序。
我使用了jSerialComm库,根据Android Studio我的代码没有错误,但是当我运行它的时候,它找不到这个库?我收到以下错误:
FATAL EXCEPTION: main Process: com.sahragard.avengrecontroller, PID: 11728 java.lang.UnsatisfiedLinkError: dlopen failed: file offset for the library "/data/user/0/com.sahragard.avengrecontroller/cache/1454627726168-libjSerialComm.so"
= file size: 0 >= 0 at java.lang.Runtime.load(Runtime.java:332) at java.lang.System.load(System.java:1069) at com.fazecast.jSerialComm.SerialPort.(SerialPort.java:181) at com.sahragard.avengrecontroller.Conn.getPorts(Conn.java:19) at com.sahragard.avengrecontroller.MainActivity.onCreate(MainActivity.java:25) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我在谷歌上搜索了好几个小时,并按照我找到的提示进行操作,但无论我做什么,总是出现同样的错误。我已经根据这篇文章添加了库: https://stackoverflow.com/a/16628496/4582696
我很感激能得到的任何帮助!提前致谢。
编辑:
MainActivity类是一个包含Swing接口(interface)的类的改编,它的代码添加在这段代码的下面
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Spinner conSpinner =(Spinner) findViewById(R.id.spinner);
String[] a = new String[Conn.getPorts().length];
for(int i=0; i<Conn.getPorts().length; i++){
a[i] = Conn.getPorts()[i].getSystemPortName();
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, a);
conSpinner.setAdapter(adapter);
final Button disconnectButton = (Button) findViewById(R.id.disconnect);
disconnectButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.disconnect();
}
});
final Button connectButton = (Button) findViewById(R.id.connect);
connectButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.connect(conSpinner.getSelectedItemPosition());
Runnable run = new Runnable() {
public void run() {
Conn.listen();
}
};
Conn.listen = new Thread(run);
Conn.listen.start();
}
});
final Button up = (Button) findViewById(R.id.upButton);
up.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.sendMsg("w");
}
});
final Button down = (Button) findViewById(R.id.downButton);
down.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.sendMsg("s");
}
});
final Button left = (Button) findViewById(R.id.leftButton);
left.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.sendMsg("a");
}
});
final Button right = (Button) findViewById(R.id.rightButton);
right.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Conn.sendMsg("d");
}
});
}
}
原始 Remote_Interface 类
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.fazecast.jSerialComm.SerialPort;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextPane;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Remote_Interface extends JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Remote_Interface frame = new Remote_Interface();
frame.setVisible(true);
// Conn.listen();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Remote_Interface() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 270, 268);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JComboBox<String> comboBox = new JComboBox<String> ();
comboBox.setBounds(20, 46, 214, 20);
for(int i=0; i<Conn.getPorts().length; i++){
comboBox.addItem(Conn.getPorts()[i].getSystemPortName());
}
contentPane.add(comboBox);
textField = new JTextField();
textField.setBounds(20, 131, 214, 20);
contentPane.add(textField);
textField.setColumns(10);
textField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Conn.sendMsg(e.getActionCommand());
textField.setText("");
}
});
JButton btnNewButton = new JButton("Send");
btnNewButton.setBounds(20, 162, 89, 23);
contentPane.add(btnNewButton);
JTextPane txtpnPleaseSelectA = new JTextPane();
txtpnPleaseSelectA.setBackground(SystemColor.control);
txtpnPleaseSelectA.setText("Please select a port to connect");
txtpnPleaseSelectA.setEditable(false);
txtpnPleaseSelectA.setBounds(10, 11, 214, 20);
contentPane.add(txtpnPleaseSelectA);
btnNewButton.setEnabled(false);
textField.setEnabled(false);
JButton btnNewButton_1 = new JButton("Connect");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Conn.connect(comboBox.getSelectedIndex());
btnNewButton.setEnabled(true);
textField.setEnabled(true);
Runnable run = new Runnable(){
public void run(){
Conn.listen();
}
};
Conn.listen = new Thread(run);
Conn.listen.start();
}
});
btnNewButton_1.setBounds(143, 77, 89, 23);
contentPane.add(btnNewButton_1);
JButton btnD = new JButton("Disconnect");
btnD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Conn.disconnect();
btnNewButton.setEnabled(false);
textField.setEnabled(false);
}
});
btnD.setBounds(20, 77, 89, 23);
contentPane.add(btnD);
}
}
和 Conn 类
import com.fazecast.jSerialComm.*;
import java.io.PrintWriter;
import java.util.Scanner;
public class Conn {
static PrintWriter out;
static SerialPort[] ports;
static SerialPort port;
static Scanner in;
static Thread listen;
public static SerialPort[] getPorts(){
ports = SerialPort.getCommPorts();
return ports;
}
public static void sendMsg(String s){
out.println(s);
out.flush();
}
public static void connect(int i){
port = ports[i];
port.openPort();
port.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
out = new PrintWriter(port.getOutputStream());
in = new Scanner(port.getInputStream());
}
public static void disconnect(){
port.closePort();
}
public static void listen(){// handle the input from the Arduino chip
while(in.hasNextLine()){
System.out.println(in.nextLine());// just print it out to the console
}
}
}
最佳答案
我遇到了同样的问题,我唯一能解决的方法是:
之后
SerialPort myPort = SerialPort.getCommPort("/dev/ttyMT2");
给出了相应的对象,没有任何UnsatisfiedLinkError。
*另一件事,如果您正在使用/dev 文件夹,则可能需要进行 android 构建,其中 SeLinux 权限模式设置为 Disabled 或 Permissive。 https://www.centos.org/docs/5/html/5.1/Deployment_Guide/sec-sel-enable-disable.html
关于java - Android - dlopen 失败 : file offset for the library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35213730/
我看过有关 CocoaPods 的指南,建议像这样导入所需的 pod 的库 header : #import 在哪里Library是库的名称(例如 #import )。 我还看到指南建议像这样导入
我正在尝试创建一个包含其他库的 PHP 库,我敢打赌我遗漏了一些基本的东西。 使用 AWS PHP SDK作为指南,我想创建一个库,在使用 Composer 安装后,它需要其他库,但是类的整个范围(包
我正在为 Android 产品开发我的 gradle 版本,以使产品风格正常工作。 我有以下项目结构: at.mkw.inlocs.android - Library Project at.mkw.i
使用@testing-library/react-hooks 我过去常常通过initialProps 传递模拟存储,正如Advanced Hooks 中提到的那样文档。假设我有一个代码: import
我试图获得一个静态链接到我的程序的音频库。我用 this灵活的包。为了让它运行,我必须按照描述构建 soloud 库 here .下载后不久,我在“build”文件夹中运行了“genie --with
我刚刚安装了 zkcm library在我的 kubuntu 机器上,我在编译 C++ 代码时遇到了问题。 我已经安装了 gmp 和 mpfr 库并检查它们是否工作;代码 mpfr_t m1, m2,
我正在尝试编译我的 native 代码。这是我的 android.mk 文件 //part1-static lib LOCAL_PATH := $(call my-dir) include $(CLE
我正在开发一个带有沙丘的大型图书馆。让我们调用这个库L . 为了避免造成大困惑,沙丘项目有许多较小的库:A , B , C , ... 这些库相互依赖。 我希望用户能够 opam install L
在 unix 之上使用 C 语言工作,我正在加载和使用共享库,如下所示: ... handle = dlopen("nameOfLib"); ... libInit(); ... libGoToSta
我试图找出一种更简单的方法来为XCode中的链接器构建阶段复制/同步框架列表。我知道我可以在Xcode中复制目标,但这是用于创建新的Cocoa Touch Unit Testing Bundle目标。
例如/lib/的描述是它包含系统的共享库文件。 图书馆到底是什么?我们谈论的库文件是否类似于在 C 中导入库?库文件中包含什么以及它们的用途是什么? 它与.dll 有什么关系 最佳答案 库只是一个代码
我有这样的目录结构 . --compile_c.sh --compile_java.sh --config.sh --execute_java.sh --run.sh --src --ccode
我正在更新一些 Makefile 以从 Make 3.81 移动到 3.82。在多个地方,原作者使用了类似这样的东西来构建静态库: all: lib$(library).a($objects) 这似乎
我是 Rust 的新手,正在尝试了解 Cargo 的东西。我在他们的常见问题解答中读到关于 "why do binaries have Cargo.lock in version control, b
我正在尝试使用 Microsoft Enterprise Library 中的 DatabaseFactory 方法。 using Microsoft.Practices.EnterpriseLibr
我刚刚升级到Xcode 5.1,突然出现一个新警告: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctool
然后新的Enterprise Library 6出来了,可以是downloaded here .我已将 EnterpriseLibrary6-binaries.exe 下载并解压缩到我的 C: 驱动器
我正在尝试将 native 库与我的 Eclipse 插件捆绑在一起。当我提供库的路径时 -Djava.library.path ,它完美无缺。 但是,当我将它添加到 MANIFEST.MF 中时文件
在我的 Android Studio 项目中,我有两个子项目/模块:一个 Android 应用程序(App1)和一个 Android 库项目(LibraryProject1)。 App1取决于 Lib
我最近使用 Google 的 Closure 编译器创建了一个 JavaScript 库:https://github.com/bvaughn/task-runner 我打算让这个库供那些也需要完整闭
我是一名优秀的程序员,十分优秀!