在Android中找不到Jar的错误

时间:2012-08-30 14:37:51

标签: android android-layout android-intent

在下面的代码中,我通过单击Project属性导入jsch jar,并添加“add external jar button”也从以下链接Add external jar添加到a​​nt全局路径中但是当我运行时程序我仍然得到“java.lang.NoClassDefFoundError:com.jcraft.jsch.JSch”

 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);
      }

     }

1 个答案:

答案 0 :(得分:0)

您应该指定在构建apk时必须导出jar:在“Java Build Path”&gt;中“订单和导出”选项卡,填写与您的罐子相对应的复选框。