- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Android 编程的新手,总的来说我缺乏编程技能。我一直在关注 Head Start 教程,尽管我知道它在技术上已被删除以进行更新或其他内容。不管怎样,我到了他们只是希望您复制并粘贴代码以使 NASA RSS 提要和 Android 应用程序相互通信的部分,但由于某些或其他原因没有任何显示。我只是得到一个白屏,并且 logcat 错误似乎对我所看到的其他应用程序没有太大影响。我使用的测试数据有效,所以我认为 xml 很好,所以也许是我的 Java。我似乎找不到任何东西。任何人都可以看到我做错了什么。整个周末都在努力。这可能是复制粘贴的代码,但我不明白。
package love.android.nasadailyimage;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.jar.Attributes;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class NasaDailyImage extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nasa_daily_image);
IotdHandler handler = new IotdHandler();
handler.processFeed();
resetDisplay(handler.getTitle(), handler.getDate(), handler.getImage(), handler.getDescription());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_nasa_daily_image, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class IotdHandler extends DefaultHandler {
private String url = "http://www.nasa.gov/rss/dyn/image_of_the_day.rss";
private boolean inUrl = false;
private boolean inTitle = false;
private boolean inDescription = false;
private boolean inItem = false;
private boolean inDate = false;
private Bitmap image = null;
private String title = null;
private StringBuffer description = null;
private String date = null;
public void processFeed() {
try {
SAXParserFactory factory =
SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(this);
InputStream inputStream = new URL(url).openStream();
reader.parse(new InputSource(inputStream));
} catch (Exception e) {
}
}
private Bitmap getBitmap(String url) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);
input.close();
return bitmap;
} catch (IOException ioe) {
return null;
}
}
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equals("url")) {
inUrl = true;
} else {
inUrl = false;
}
if (localName.startsWith("item")) {
inItem = true;
} else if (inItem) {
if (localName.equals("title")) {
inTitle = true;
} else {
inTitle = false;
}
if (localName.equals("description")) {
inDescription = true;
} else {
inDescription = false;
}
if (localName.equals("pubDate")) {
inDate = true;
} else {
inDate = false;
}
}
}
public void characters(char ch[], int start, int length) {
String chars = new String(ch).substring(start, start + length);
if (inUrl && url == null) {
image = getBitmap(chars);
}
if (inTitle && title == null) {
title = chars;
}
if (inDescription) {
description.append(chars);
}
if (inDate && date == null) {
date = chars;
}
}
public Bitmap getImage() {
return image;
}
public String getTitle() {
return title;
}
public StringBuffer getDescription() {
return description;
}
public String getDate() {
return date;
}
}
private void resetDisplay(String title, String date, Bitmap image, StringBuffer description){
TextView titleView = (TextView) findViewById(R.id.imageTitle);
titleView.setText(title);
TextView dateView = (TextView) findViewById(R.id.imageDate);
dateView.setText(date);
ImageView imageView = (ImageView) findViewById(R.id.imageDisplay);
imageView.setImageBitmap(image);/////////////////////////////////////////
TextView descriptionView = (TextView) findViewById(R.id.imageDescription);
descriptionView.setText(description);
}
}
XML 以防有帮助
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".NasaDailyImage">
<TextView
android:id="@+id/imageTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/image_title" />
<TextView
android:id="@+id/imageDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/image_date" />
<ImageView
android:id="@+id/imageDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/galaxy"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/imageDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/image_description" />
</LinearLayout>
</ScrollView>
任何帮助将不胜感激。我会问这里的人,但在我的国家“纳米比亚”,很少有人能接触到我能接触到的 android 编程。
我的 S4 设备上的 LogCat
04-20 11:07:17.204 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection
04-20 11:07:17.204 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getTextBeforeCursor on inactive InputConnection
04-20 11:07:17.209 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
04-20 11:07:17.209 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getTextAfterCursor on inactive InputConnection
04-20 11:12:38.244 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getExtractedText on inactive InputConnection
04-20 11:12:38.244 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getTextBeforeCursor on inactive InputConnection
04-20 11:12:38.244 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getSelectedText on inactive InputConnection
04-20 11:12:38.249 25660-25660/love.android.nasadailyimage W/IInputConnectionWrapper﹕ getTextAfterCursor on inactive InputConnection
04-20 11:16:06.154 30742-30742/love.android.nasadailyimage W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-20 11:16:06.154 30742-30742/love.android.nasadailyimage I/PersonaManager﹕ getPersonaService() name persona_policy
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 12208: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 12214: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-20 11:16:06.229 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-20 11:16:06.234 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-20 11:16:06.234 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 9779: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-20 11:16:06.234 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 392: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 414: Landroid/content/res/TypedArray;.getType (I)I
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-20 11:16:06.244 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
04-20 11:16:06.249 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 355: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
04-20 11:16:06.249 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-20 11:16:06.249 30742-30742/love.android.nasadailyimage I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
04-20 11:16:06.249 30742-30742/love.android.nasadailyimage W/dalvikvm﹕ VFY: unable to resolve virtual method 357: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
04-20 11:16:06.249 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-20 11:16:06.369 30742-30742/love.android.nasadailyimage D/dalvikvm﹕ GC_FOR_ALLOC freed 130K, 6% free 16994K/18052K, paused 15ms, total 15ms
04-20 11:16:06.389 30742-30742/love.android.nasadailyimage I/dalvikvm-heap﹕ Grow heap (frag case) to 28.887MB for 11943952-byte allocation
04-20 11:16:06.404 30742-30751/love.android.nasadailyimage D/dalvikvm﹕ GC_FOR_ALLOC freed 4K, 4% free 28654K/29720K, paused 12ms, total 12ms
04-20 11:16:06.479 30742-30742/love.android.nasadailyimage I/System.out﹕ main(HTTPLog):SmartBonding Enabling is false, log to file is false, DBG is false
04-20 11:16:06.594 30742-30742/love.android.nasadailyimage D/OpenGLRenderer﹕ Enabling debug mode 0
AndroidManifest 请求
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="love.android.nasadailyimage" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".NasaDailyImage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
构建.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "love.android.nasadailyimage"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
编辑:添加了我的 LogCat 和我的 AndroidManifest
最佳答案
在 StackOverflow 上发现了一个问题,该问题遵循与您相同的教程。也许这对你有帮助
Android Head First "NASA daily image App"
如前所述,您应该使用 AsyncTask,并在请求返回时处理请求 (onPostExecute)。您的代码的问题是,您发送了一个请求,并且在您调用 resetDisplay 之后,响应还没有返回...这就是您看到空白屏幕的原因。
关于java - 无法让 Android Tutorial 工作,初级程序员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29744861/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
我是 NES 开发新手,我发现 Nerdy Nights 教程非常方便,但它使用 nesasm。据我了解,ASM6比nesasm好得多。我可以在哪里查找类似的教程吗? 另外,有官方的 ASM6 页面吗
有没有关于 CakePHP 3 cookie 组件的好教程。 我是 CakePHP 的新手和 Cookie以及。我正在写一个 e-commerce在 CakePHP 3.2 中的应用并想用 Cooki
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
我正尝试在我的应用中做一个初始教程,如下图所示: 你知道这个功能的名称吗?为了找到它的教程。 最佳答案 你需要两件事 ViewPager 自定义 ViewPager 指示器 - 在 Canvas 中绘
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在标题中解释这一点有点困难,但我想做的是制作“交互式”教程,用户单击他想要清洁或清洁的区域或产品,然后弹出另一个框提供信息,当该部分完成后,您继续使用另一个盒子,依此类推...所以我最终得到了一个接一
本文整理了Java中de.jonashackt.tutorial.controller.WeatherServiceController类的一些代码示例,展示了WeatherServiceContro
我目前正在尝试通过编写一些 DirectX 10 和 OpenGL 3.3 在 DirectX 和 OpenGL 之间做出决定。我已经完成了 DirectX 的设置,链接和编译相当容易。 OpenGl
我是语义网的新手。我想开始创建一些基本的 RDF 文档并发布它们以了解它是如何工作的。我找到了很多关于概念、词汇等的信息,但我找不到任何与开发相关的东西,比如开发是什么需要环境,需要什么工具。我来自
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等建议的问题。您可以编辑问题,以便可以用事实和引用来回答它。 7年前关
我想在屏幕布局上重叠一些解释界面的 View ,如下图 所示 因此将布局更改为: RootLayout AppLayout TutorialLayout (FrameLayout) 我
正如标题所说,我对 CakePHP 2 的 Acl 教程有疑问。我完全按照教程中提到的方式完成了所有操作,但仍然无法正常工作。 我知道互联网上有很多人对本教程也有疑问,但我找不到任何博客条目或与我有同
我想使用 Cytoscape.js ,所以我复制粘贴了他们的 tutorial : var cy = cytoscape({ container: document.getElementByI
大家晚上好,Stackoverflow 领主们和女士们, 我正在尝试开发一个 Layar 层以在我的工作中使用,但我一开始就遇到了一些困难。这是场景 我已经下载了Layar为本教程提供的示例代码,He
我正在尝试使用 youtube 教程来学习 ajax。 但是,我在这里创建的所有内容并不像视频中显示的那样有效。我已经仔细检查了代码好几次了。 这是我的 jsfiddle html 代码。 js代码在
我正在使用这个颜色选择器来更改元素的颜色:http://www.script-tutorials.com/html5-color-picker-canvas/ .单击一个元素会打开颜色选择器,选择一种
我最近了解到: glBegin(GL_TRIANGLES); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVerte
到目前为止,我已经了解到,当父对象被删除时,Qt 会释放所有子对象的内存。此外,通常不必关心在堆栈上创建的对象(即不是指针)的内存管理。 现在,当我做得很好的时候"AddressBook" tutor
是否有任何好的教程概述了 Facebook 应用程序经过验证的架构模式?我在他们的开发文档中找到的大部分资源都是面向 hello world 的。我正在寻找一些东西(文章、书籍、截屏视频等)来概述 F
我是一名优秀的程序员,十分优秀!