简体   繁体   English

Android Project不适用于外部JAR或Project Reference

[英]Android Project will not work with external JAR or Project Reference

I have a semester long project that I have been working on in Android with a four person group. 我有一个为期一个学期的项目,我一直在与四个人的小组一起在Android中进行开发。 It is due tomorrow. 明天到期。 I was planning on using JDBC for Android, but I have run into an ugly problem I had seen before. 我当时计划将JDBC用于Android,但遇到了一个我以前见过的丑陋问题。 No matter what I do, my Android will not recognize external references. 无论我做什么,我的Android 都无法识别外部引用。 For awhile I avoided the problem by copying source code into my project. 有一段时间我通过将源代码复制到我的项目中来避免该问题。

However, with JDBC, I need a JAR Driver to in order to connect to the MySQL Database. 但是,对于JDBC,我需要一个JAR驱动程序才能连接到MySQL数据库。 So you are aware, I am adding the JAR by: 所以您知道,我通过以下方式添加了JAR:

  1. Creating a folder 建立资料夹
  2. Importing the JAR into that folder 将JAR导入到该文件夹
  3. Adding the JAR to the BuildPath in the Android Project. 将JAR添加到Android项目中的BuildPath中。

I also tried adding an external Java Project by adding it to the BuildPath. 我还尝试通过将外部Java项目添加到BuildPath中来添加它。 There were no Compile errors, but I got ClassNotFound errors when the code executed on my (Ice Cream Sandwich) phone. 没有编译错误,但是在我的(冰淇淋三明治)手机上执行代码时出现ClassNotFound错误。 The project is in Android 2.2. 该项目在Android 2.2中。 I have heard making an Android Library project will solve this, but I am not interested in that solution as it defeats the purpose of the project reference in my case. 我听说制作一个Android Library项目可以解决此问题,但是我对这种解决方案不感兴趣,因为它违反了我的项目引用目的。

With the JDBC Driver, the following RuntimeException was thrown in my project here: 使用JDBC驱动程序,在我的项目中抛出了以下RuntimeException:

private final static String driver = "com.mysql.jdbc.Driver";
private final static String userName = "sqluser";
private final static String passwd = "sqlpw";

public Query() {
    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
//          System.err
//                  .println("error in DB connection: can not find the DB driver");
        throw new RuntimeException("Driver not found");
    }

The code works fine as a Java Application. 该代码可以作为Java应用程序正常工作。

Any solution that works would be highly appreciated. 任何有效的解决方案将不胜感激。 Since the project is due tomorrow, it doesn't have to be the most elegant approach. 由于该项目将于明天到期,因此它不一定是最优雅的方法。 Also (not that it matters), my project is connected to a SVN repository via SubClipse. 同样(无关紧要),我的项目通过SubClipse连接到SVN存储库。 Thanks in advance! 提前致谢!

我不确定要将JAR放入哪个文件夹,但是对于android项目,您必须将其放入“ libs”文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM