- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Activity 代码:
package com.example.ma18uus.myapplication;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
public class weatherAPI {
public static void main() throws Exception {
//Main url
String main_url = "http://api.weatherapi.com/v1/";
//Live or Weekly forecast
String live_weather = "current.xml?key=";
//String sevendays_weather = "orecast.xml?key=";
//API Key + q
String API_Key = "APIKEY&q=";
//Location Setters
String location = "London";
InputSource inSource = null;
InputStream in = null;
XMLReader xr = null;
try
{
// Turn the string into a URL object
String complete_url = main_url + live_weather + API_Key + location;
URL urlObject = new URL(complete_url);
// Open the stream (which returns an InputStream):
in = urlObject.openStream();
/** Now parse the data (the stream) that we received back ***/
// Create an XML reader
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
xr = parser.getXMLReader();
// Tell that XML reader to use our special Google Handler
Handler ourSpecialHandler = new Handler();
xr.setContentHandler(ourSpecialHandler);
// We have an InputStream, but let's just wrap it in
// an InputSource (the SAX parser likes it that way)
inSource = new InputSource(in);
// And parse it!
xr.parse(inSource);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(SAXException se)
{
se.printStackTrace();
}
}
}
天气 View 类:
package com.example.ma18uus.myapplication;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
public class weatherView extends AppCompatActivity {
//Main url
static final String main_url = "http://api.weatherapi.com/v1/";
//Live or Weekly forecast
static final String live_weather = "current.xml?key=";
//String sevendays_weather = "orecast.xml?key=";
//API Key + q
static final String API_Key = "c3bdfadb90d5452bb8003318201801&q=";
//Location Setters
static final String location = "London";
//Complete url for todays forecast
static final String URLT = main_url + live_weather + API_Key + location;
//XML node keys
static final String KEY_ITEM = "root";//parent node
static final String KEY_NAME = "name";//name of city, string
static final String KEY_WIND_MPH = "wind_mph";//wind mph, float
static final String KEY_WIND_KPH = "wind_kph";//wind kph, float
static final String KEY_C = "temp_c";//Temperature Celsius, int
static final String KEY_C_FEELS = "feelslike_c";//Temperature feeling Celsius, float
static final String KEY_F = "temp_f";//Temperature Fahrenheit, int
static final String KEY_F_FEELS = "feelslike_f";//Temperature feeling Fahrenheit, float
static final String KEY_HUMIDITY = "humidity";//Humidity Level, int
static final String KEY_CONDITION_TEXT = "text";//Weather Condition i.e. cloudy, sunny, clear, string
ArrayList<HashMap<String, String>> menuItems;
private TextView txt;
String xml;
//@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather_view);
menuItems = new ArrayList<HashMap<String, String>>();
txt = (TextView) findViewById(R.id.weather_window);
new weatherTask().execute();
// weatherTask.parseXML();
}
private class weatherTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... voids) {
parseXML();
return null;
}
private void parseXML(){
XmlPullParserFactory parserFactory;
try {
parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
try {
InputStream is = new URL(URLT).openStream();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(is, null);
processParsing(parser);
} catch (IOException e) {
e.printStackTrace();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
}
}
private void processParsing(XmlPullParser parser) throws IOException, XmlPullParserException{
ArrayList<WeatherConditions> weather = new ArrayList<>();
int eventType = parser.getEventType();
WeatherConditions currentWeather = null;
while(eventType != XmlPullParser.END_DOCUMENT){
String sName = null;
switch(eventType){
case XmlPullParser.START_TAG:
sName = parser.getName();
if ("root".equals(sName)){
currentWeather = new WeatherConditions();
weather.add(currentWeather);
}else if (currentWeather != null){
if ("name".equals(sName)){
currentWeather.name = parser.nextText();
}
else if ("wind_mph".equals(sName)){
currentWeather.wind_mph = parser.nextText();
}else if ("wind_kph".equals(sName)){
currentWeather.wind_kph = parser.nextText();
}else if ("celsius".equals(sName)){
currentWeather.celsius = parser.nextText();
}else if ("feelsCelsius".equals(sName)){
currentWeather.feelsCelsius = parser.nextText();
}else if ("fahrenheit".equals(sName)){
currentWeather.fahrenheit = parser.nextText();
}else if ("feelsFahrenheit".equals(sName)){
currentWeather.feelsFahrenheit = parser.nextText();
}else if ("humidity".equals(sName)){
currentWeather.humidity = parser.nextText();
}else if ("text".equals(sName)){
currentWeather.condition_text = parser.nextText();
}
}
break;
}
eventType = parser.next();
}
printWeather(weather);
}
private void printWeather(ArrayList<WeatherConditions> weather){
StringBuilder builder = new StringBuilder();
for (WeatherConditions weatherC : weather){
builder.append(weatherC.name).append("\n").append(weatherC.wind_mph).append("\n").append(weatherC.wind_kph).append("\n").append(weatherC.celsius).append("\n").append(weatherC.feelsCelsius).
append("\n").append(weatherC.fahrenheit).append("\n").append(weatherC.feelsFahrenheit).append("\n").append(weatherC.humidity).append("\n").append(weatherC.condition_text).append("\n");
}
txt.setText(builder.toString());
}
}
}
当前 list 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ma18uus.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.google.android.actions"
android:resource="@xml/network_security_config" />
<activity android:name=".weatherView" />
<activity android:name=".ClothesApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HoodiesSweatShirts" />
<activity android:name=".CoatsJackets" />
<activity android:name=".Shirts" />
<activity android:name=".Trousers" />
<activity android:name=".Shoes" />
<activity android:name=".Accessories" />
</application>
</manifest>
当前错误输出:
01/24 16:15:28: Launching 'app' on Pixel 2 API 29.
$ adb shell am start -n "com.example.ma18uus.myapplication/com.example.ma18uus.myapplication.ClothesApp" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Waiting for process to come online...
Connected to process 22318 on device 'Pixel_2_API_29 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/s.myapplicatio: Not late-enabling -Xcheck:jni (already on)
W/main: type=1400 audit(0.0:268): avc: granted { read } for name="u:object_r:net_dns_prop:s0" dev="tmpfs" ino=8398 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:net_dns_prop:s0 tclass=file
E/s.myapplicatio: Unknown bits set in runtime_flags: 0x8000
W/s.myapplicatio: Unexpected CPU variant for X86 using defaults: x86
I/s.myapplicatio: The ClassLoaderContext is a special shared library.
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
W/RenderThread: type=1400 audit(0.0:269): avc: denied { write } for name="property_service" dev="tmpfs" ino=8445 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/s.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/s.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/HostConnection: HostConnection::get() New Host Connection established 0xdc973fa0, tid 22351
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation: eglCreateContext: 0xe7fa9ac0: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xe7fa9ac0: ver 3 0 (tinfo 0xe7fe50e0)
W/Gralloc3: mapper 3.x is not supported
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0xdc975cb0, tid 22351
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/eglCodecCommon: allocate: Ask for block of size 0x1000
allocate: ioctl allocate returned offset 0x3ff805000 size 0x2000
D/EGL_emulation: eglMakeCurrent: 0xe7fa9ac0: ver 3 0 (tinfo 0xe7fe50e0)
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@dffd53e
D/NetworkSecurityConfig: Using Network Security Config from resource network_security_config debugBuild: true
W/System.err: java.net.SocketException: socket failed: EPERM (Operation not permitted)
W/System.err: at java.net.Socket.createImpl(Socket.java:492)
W/System.err: at java.net.Socket.getImpl(Socket.java:552)
at java.net.Socket.setSoTimeout(Socket.java:1180)
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:248)
at java.net.URL.openStream(URL.java:1072)
at com.example.ma18uus.myapplication.weatherView$weatherTask.parseXML(weatherView.java:85)
at com.example.ma18uus.myapplication.weatherView$weatherTask.doInBackground(weatherView.java:73)
at com.example.ma18uus.myapplication.weatherView$weatherTask.doInBackground(weatherView.java:68)
at android.os.AsyncTask$3.call(AsyncTask.java:378)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
D/EGL_emulation: eglMakeCurrent: 0xe7fa9ac0: ver 3 0 (tinfo 0xe7fe50e0)
我收到有关权限的错误,但我已经在 list 文件上设置了所需的权限,所以我不明白我做错了什么或我必须修复什么,有人可以解释一下这种情况吗?
另外,我也遇到了一些关于 doinbackground 的错误,我也不明白,是因为权限错误,我也遇到了错误,还是我做错了什么?
编辑#1:
似乎我通过您给我的链接的权限解决了这个问题,但现在看来我在我的weatherview类的doinbackground中出现了致命异常。
编辑#2:当我使用 list 1 时,我收到错误输出 1,这给了我一个权限错误,但是当我使用 list 2 时,它消除了权限错误,我收到一个标签错误:/
编辑#3:更新了错误输出和 list 文件以匹配当前文件、输出
提前致谢!!
最佳答案
标签名称network_security_config
将其重命名为network-security-config
编辑 1:将其更改为:<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">www.weatherapi.com</domain> </domain-config> </network-security-config>
编辑 2:对于第二个错误输出,它告诉您正在使用(带下划线)而不是(带破折号),请确保它们在开始和结束标记中都是破折号。
关于java - 不应该出现的权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59895875/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!