当前位置: 首页 > 知识库问答 >
问题:

(Android studio)升级4.1.2>4.2.0后出错

能正青
2023-03-14

在android版本为4.1.2的时候,这段代码运行良好。但是在4.2.0之后,代码就不工作了,下面是我的代码

import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import java.util.UUID;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import android.os.Bundle;
import android.widget.TextView;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            String accessKey = ("code erased");//api key 1
            String secretKey = ("code erased");//api key 2
            String serverUrl = ("https://api.upbit.com");

            Algorithm algorithm = Algorithm.HMAC256(secretKey);
            String jwtToken = JWT.create()
                    .withClaim("access_key", accessKey)
                    .withClaim("nonce", UUID.randomUUID().toString())
                    .sign(algorithm);

            String authenticationToken = "Bearer " + jwtToken;
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet(serverUrl + "/v1/accounts");
            request.setHeader("Content-Type", "application/json");
            request.addHeader("Authorization", authenticationToken);

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();

            //System.out.println(EntityUtils.toString(entity, "UTF-8"));

            double balance_total = 0.0;
            JsonParser jsonParser = new JsonParser();
            JsonArray jsonArray = (JsonArray) jsonParser.parse(EntityUtils.toString(entity, "UTF-8"));
            for (int i = 0; i < jsonArray.size(); i++) {
                JsonObject object = (JsonObject) jsonArray.get(i);
                Double balances = object.get("balance").getAsDouble();
                balance_total += balances;
            }
            
        }
        catch (Exception e) {
                e.printStackTrace();
        }
    }
}

我的依赖是

implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
implementation 'com.auth0.android:jwtdecode:2.0.0'
    api 'io.jsonwebtoken:jjwt-api:0.11.2'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
    runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.2') { exclude group: 'org.json', module: 'json'}
    runtimeOnly 'org.bouncycastle:bcprov-jdk15on:1.60'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.auth0:java-jwt:3.15.0'
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    implementation 'com.google.code.gson:gson:2.8.6'
    androidTestImplementation "com.github.tomakehurst:wiremock-standalone:2.26.3"
W/pclass.apitest: Accessing hidden method Ljava/lang/Thread;-><clinit>()V (blacklist, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->EMPTY_STACK_TRACE:[Ljava/lang/StackTraceElement; (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->SUBCLASS_IMPLEMENTATION_PERMISSION:Ljava/lang/RuntimePermission; (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->lock:Ljava/lang/Object; (greylist, linking, allowed)
W/pclass.apitest: Accessing hidden field Ljava/lang/Thread;->daemon:Z (greylist, linking, allowed)
    Accessing hidden field Ljava/lang/Thread;->stillborn:Z (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->threadLocals:Ljava/lang/ThreadLocal$ThreadLocalMap; (greylist, linking, allowed)
    Accessing hidden field Ljava/lang/Thread;->inheritableThreadLocals:Ljava/lang/ThreadLocal$ThreadLocalMap; (greylist, linking, allowed)
    Accessing hidden field Ljava/lang/Thread;->systemDaemon:Z (blacklist, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->started:Z (greylist-max-o, linking, denied)
W/pclass.apitest: Accessing hidden field Ljava/lang/Thread;->blockerLock:Ljava/lang/Object; (greylist-max-o, linking, denied)
    Accessing hidden method Ljava/lang/Thread;->nextThreadNum()I (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->stillborn:Z (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->systemDaemon:Z (blacklist, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->started:Z (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->blockerLock:Ljava/lang/Object; (greylist-max-o, linking, denied)
    Accessing hidden method Ljava/lang/Thread;->nextThreadNum()I (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->stillborn:Z (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->systemDaemon:Z (blacklist, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->started:Z (greylist-max-o, linking, denied)
    Accessing hidden field Ljava/lang/Thread;->blockerLock:Ljava/lang/Object; (greylist-max-o, linking, denied)
.
.
.

共有1个答案

湛财
2023-03-14

你正在主线程上执行一个网络请求,这是一个阻塞进程,而android不允许在主线程上执行网络请求,你应该在后台线程上执行它,它不会阻塞UI处理。

 类似资料:
  • 在Android Studio的提示下,我将我项目的Android Gradle插件从4.2.0-beta02升级到4.2.0-beta03。现在,每次同步构建文件时,都会出现以下构建错误: 此错误以前没有显示。下面是生成错误的模块的构建文件: 那么,这是最新AGP版本的一个bug,还是我的构建文件有什么问题,以前被忽略了,但现在被标记了?(我试着注释掉块的整个主体,但错误依然存在。我还试着使缓存

  • 使用以前版本的 Android Studio 与候选版本 4(12 月 4 日)或更高版本一起正常工作: 在我看来和更新有关 这看起来很相似:https://github.com/robolectric/robolectric/issues/1136 编辑 工作:编译'com.google.android.gms:playservices:6.1。'

  • 我正在更新我们应用程序中落后的一些maven依赖项,从flyway maven插件4.2.0升级时遇到了一个问题,我们的reset和migrate make命令失败了,我找不到任何有用的结果。 最初,我试图从4.2.0转移到5.2.4。当我无法解决我的错误时,我退回到5.0.0的单个版本。在5.0.0的发行说明之后,我将添加到我的flyway-$env.properties文件中,并更新了我的Ma

  • 从带有SP1的AEM 6.2升级到AEM 6.4后,很少有软件包未安装。旧版本处于已安装状态。 对于新软件包,显示消息为“似乎安装了另一个版本:”请参见下面的屏幕截图。 正因为如此,我可以看到很少的脚本没有更新最新的API。例如AEM 6.4升级实例:

  • 问题内容: 我有一个用于签署XML文档的Java应用程序。将Java升级到最新版本(Java7u25)后,它将停止工作。我收到以下错误: 恢复为java7u21解决了该问题。XML Dig Sig API中是否有任何导致此错误的更改? 问题答案: 这里同样的问题。由于不断发展,似乎是JVM内部的错误。 我已经将其归结为 在Java 7u21及之前的版本中: 在Java 7u25中: 指的是XML

  • 运行Firebase upgrade命令后,我尝试在模拟器中运行我的应用程序,出现了以下错误消息: 在调试模式下在 sdk gphone64 x86 64 上启动 lib\main.dart...运行 Gradle 任务 'assembleDebug'... /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.24.