Android中未找到Jar错误
在下面的代码中,我通过单击项目属性导入了jsch jar,并通过添加“添加外部jar按钮”从以下链接添加到ant全局路径中,但当我运行程序时,仍然会得到“java.lang.NoClassDefFoundError:com.jcraft.jsch.jsch”Android中未找到Jar错误,android,android-layout,android-intent,Android,Android Layout,Android Intent,在下面的代码中,我通过单击项目属性导入了jsch jar,并通过添加“添加外部jar按钮”从以下链接添加到ant全局路径中,但当我运行程序时,仍然会得到“java.lang.NoClassDefFoundError:com.jcraft.jsch.jsch” package android_jsch.com; 导入java.io.PrintStream; 导入java.util.ArrayList; 导入java.util.List; 导入android.app.Activity; 导入com.
package android_jsch.com;
导入java.io.PrintStream;
导入java.util.ArrayList;
导入java.util.List;
导入android.app.Activity;
导入com.jcraft.jsch.*;
导入android.os.Bundle;
导入android.widget.EditText;
公共类Android_JSCHAActivity扩展了活动{
编辑文本ip、用户名、密码;
@凌驾
创建时的公共void(Bundle savedInstanceState){
List命令=new ArrayList();
commands.add(“touch/tmp/test1.txt”);
commands.add(“touch/tmp/test2.txt”);
commands.add(“touch/tmp/test3.txt”);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rd);
试一试{
JSch JSch=新的JSch();
session.connect();
Channel-Channel=session.openChannel(“shell”);//仅限shell
channel.setOutputStream(系统输出);
PrintStream shellStream=新的PrintStream(channel.getOutputStream());//为方便起见,PrintStream
channel.connect();
用于(字符串命令:命令){
println(命令);
shellStream.flush();
}
睡眠(5000);
通道断开();
session.disconnect();
}捕获(例外e){
System.err.println(“错误:通过shell连接到”+ip.getText().toString());
e、 printStackTrace();
}
}
私有静态void setUpHostKey(会话){
java.util.Properties config=new java.util.Properties();
配置放置(“检查”、“否”);
session.setConfig(config);
}
}
您应该指定在构建apk时必须导出jar:在“Java构建路径”>“订单和导出”选项卡中,填写与您的jar对应的复选框。是的,我确实在那里选中了复选框,但错误仍然存在。是否在完成后尝试清理您的项目?是的,并且已运行。请稍候,我会让您知道我在订单和导出选项卡中选择了什么。是的,在我多次清理后,它现在正在工作。但是应用程序似乎没有连接到外部系统。知道为什么吗?现在可能是另一个问题了。。。如有必要,尝试识别它并发布新问题(带有日志跟踪)
package android_jsch.com;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import com.jcraft.jsch.*;
import android.os.Bundle;
import android.widget.EditText;
public class Android_jschActivity extends Activity {
EditText ip,username,password;
@Override
public void onCreate(Bundle savedInstanceState) {
List<String> commands = new ArrayList<String>();
commands.add("touch /tmp/test1.txt");
commands.add("touch /tmp/test2.txt");
commands.add("touch /tmp/test3.txt");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
rd);
try {
JSch jsch = new JSch();
session.connect();
Channel channel=session.openChannel("shell");//only shell
channel.setOutputStream(System.out);
PrintStream shellStream = new PrintStream(channel.getOutputStream()); // printStream for convenience
channel.connect();
for(String command: commands) {
shellStream.println(command);
shellStream.flush();
}
Thread.sleep(5000);
channel.disconnect();
session.disconnect();
} catch (Exception e) {
System.err.println("ERROR: Connecting via shell to "+ip.getText().toString());
e.printStackTrace();
}
}
private static void setUpHostKey(Session session) {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
}
}