![](/img/trans.png)
[英]Android Studio 4.1.2 unable to run android studio on emulator or real device
[英](Android studio) Error after upgrade 4.1.2 > 4.2.0
當 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"
I'm using commons-codes 1.10v as a jar file instead of implementation because I use two apis and other api doesn't work with commons-codec implementation.(And it occurs duplicate class if i use jar file and dependencies both)
錯誤是這樣發生的
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)
.
.
.
出現大量“訪問隱藏字段或方法”錯誤
android 更新有什么問題還是我做錯了什么?
您正在主線程上執行網絡請求,這是一個阻塞進程,並且 android 不允許在主線程上執行網絡請求,您應該在不會阻塞 UI 處理的后台線程上執行它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.