FATAL EXCEPTION: main
Process: com.example.dell.ora, PID: 24491
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
at java.net.InetAddress.getAllByName(InetAddress.java:215)
at com.squareup.okhttp.Dns$1.lookup(Dns.java:39)
at com.squareup.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:175)
at com.squareup.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:141)
at com.squareup.okhttp.internal.http.RouteSelector.next(RouteSelector.java:83)
at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:174)
at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.squareup.okhttp.Call.getResponse(Call.java:286)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
at com.squareup.okhttp.Call.execute(Call.java:80)
at com.ibm.watson.developer_cloud.service.WatsonService.execute(WatsonService.java:122)
at com.ibm.watson.developer_cloud.service.WatsonService.executeRequest(WatsonService.java:183)
at com.ibm.watson.developer_cloud.personality_insights.v2.PersonalityInsights.getProfile(PersonalityInsights.java:119)
at com.example.dell.ora.AnalyzerFragment.onCreateView(AnalyzerFragment.java:39)
我正在尝试通过检查我的片段中的文档来运行个性洞察力
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View x = inflater.inflate(R.layout.fragment_analyzer, container, false);
PersonalityInsights service = new PersonalityInsights();
service.setUsernameAndPassword("", "");
service.setEndPoint("https://gateway.watsonplatform.net/personality-insights/api");
EditText content= x.findViewById(R.id.content);
TextView output= x.findViewById(R.id.output);
// String text = content.getText().toString();
String text =getResources().getString(R.string.demo);
Profile profile = service.getProfile(text);
System.out.println(profile);
return x;
}
为此,我插入了我的 gradle 文件
compile 'com.squareup.okhttp3:okhttp:3.10.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.ibm.watson.developer_cloud:java-sdk:2.10.0'
有没有人遇到过这个错误?可以证明我做错了什么吗?提前谢谢你!