本文介绍了Android JDBC 连接导致 ctahttp 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试建立从我的 Android 应用程序到在我的 raspberry pi 上运行的 MySQL 服务器的连接.

Im currently trying to establish a connection from my Android app to a MySQL server running on my raspberry pi.

我通过将库添加到模块菜单中的依赖项来正确地将库添加到 android studio.

I added the library to android studio correctly by adding it's into the dependencys in the module menu.

我在我的程序中实现了这样的 JDBC 方法.

I implemented the JDBC-method like this into my program.

 public void readDatabase(String query)throws  Exception{

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection("jdbc:mysql://192.168.0.101/mydb","user","mypassword");

            statement = connection.createStatement();

            resultSet = statement.executeQuery(query);

            System.out.println(resultSet);

        }catch (ClassNotFoundException e){

            e.printStackTrace();

        }finally {
            close();
        }

    }

    private void close(){
        try {
            if (resultSet != null){
                resultSet.close();
            }

            if (statement != null){
                statement.close();
            }

            if ( connection != null){
                connection.close();
            }
        }catch (Exception e){

        }
    }

每次我启动程序时,我都会收到一个找不到类的错误.它说:

Every time I fire up the program I get an class not found error.It says :

W/System: ClassLoader 引用了未知路径:system/framework/mediatek-cta.jarI/System.out: e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp

我尝试以不同的方式搜索问题,但我无法弄清楚问题出在哪里.
我什至不知道 cta 课是什么.也许有人可以在这里帮助我.

I tried to search in different ways for the problem but I can not figure out where the problem is.
I don't even know what the cta class is. Maybe someone can help me out here.

推荐答案

CTA = China Type Approval,这是联发科在 Android 中添加的用于测试目的的内容.

CTA = China Type Approval, this is something that Mediatek adds in Android for testing purpose.

您的错误发生在可能使用 okhttpapache-httpSocketDriverManager.getConnection() 中> Android 的 libcore 中的类来执行它的请求.

Your error is happening in DriverManager.getConnection() that probably uses okhttp, apache-http or Socket class in Android's libcore to do its requests.

Mediatek 修补了这些库以添加对 HTTP 请求的控制.它尝试动态加载 /system/framework/mediatek-cta.jar 中定义的一些方法,但它可能不存在或在您的 android 设备的文件系统上无法访问.

Mediatek patched these libraries for adding a control of HTTP requests. It tries to load dynamically some methods defined in /system/framework/mediatek-cta.jar but it is probably absent or not accessible on your android device's file system.

我看到 5 个解决方案:

I see 5 solutions :

  1. 通过 OTA 或通过 adb remount 添加适当的 mediatek-cta.jar(如果您使用的是自定义/root ROM)
  2. 使用具有相同应用程序源代码的其他设备(非基于 Mediatek 的设备不会出现该问题).
  3. 正在通过官方 OTA 更新升级您的操作系统,并希望设备制造商解决该问题.
  4. 自己重新构建和自定义操作系统,并进行以下修改
    • 确保将 medatek-cta 添加到 PRODUCT_PACKAGESPRODUCT_BOOT_JARS
    • 删除 libcore、okhttp 和 apache-http 中的钩子.
  1. Add an appropriate mediatek-cta.jar via OTA or via adb remount if you are on a custom/rooted ROM
  2. Use another device with the same application's source code (a non- Mediatek based device would not have that issue).
  3. Upgrading your OS via an official OTA update and hope device manufacturer fixed the issue.
  4. Rebuild and customize the OS by yourself with the following modifications
    • Make sure medatek-cta is added to PRODUCT_PACKAGES and PRODUCT_BOOT_JARS
    • Remove the hooks in libcore, okhttp and apache-http.

这篇关于Android JDBC 连接导致 ctahttp 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 23:20