android.app.SuperNotCalledException(错误)
我是android新手。我正在尝试测试rss提要阅读器,我收到了这个错误消息 原因:android.app.SuperNotCalledException:活动 错误日志cat如下所示:android.app.SuperNotCalledException(错误),android,Android,我是android新手。我正在尝试测试rss提要阅读器,我收到了这个错误消息 原因:android.app.SuperNotCalledException:活动 错误日志cat如下所示: 11-27 07:08:04.192: E/AndroidRuntime(1471): FATAL EXCEPTION: AsyncTask #1 11-27 07:08:04.192: E/AndroidRuntime(1471): java.lang.RuntimeException: An error o
11-27 07:08:04.192: E/AndroidRuntime(1471): FATAL EXCEPTION: AsyncTask #1
11-27 07:08:04.192: E/AndroidRuntime(1471): java.lang.RuntimeException: An error occured while executing doInBackground()
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.os.AsyncTask$3.done(AsyncTask.java:278)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.lang.Thread.run(Thread.java:856)
11-27 07:08:04.192: E/AndroidRuntime(1471): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:3939)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:701)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.View.requestLayout(View.java:12555)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.View.requestLayout(View.java:12555)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.View.requestLayout(View.java:12555)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.View.requestLayout(View.java:12555)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.view.View.requestLayout(View.java:12555)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.widget.AbsListView.requestLayout(AbsListView.java:1690)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.widget.ListView.setAdapter(ListView.java:488)
11-27 07:08:04.192: E/AndroidRuntime(1471): at com.example.testrss.ConnectToServer.doInBackground(ConnectToServer.java:78)
11-27 07:08:04.192: E/AndroidRuntime(1471): at android.os.AsyncTask$2.call(AsyncTask.java:264)
11-27 07:08:04.192: E/AndroidRuntime(1471): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
以下是NPRNewsDetails.java代码:
package com.example.testrss;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class NPRNewsDetails extends Activity {
// a main category subject has already been selected by the user
// (data <"urlCaption", "urlAddress"> comes in a bundle sent
// by main, access web-feed and show corresponding headlines
ArrayList<SingleNewsItem> newsList = new ArrayList<SingleNewsItem>();
ArrayAdapter<String> aa;
ListView myListView;
String urlAddress = "";
String urlCaption = "";
SingleNewsItem selectedNewsItem;
Context context = getApplication();
ConnectToServer cNTS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListView = (ListView) this.findViewById(R.id.myListView);
// create a local Intent handler (needed to process input parameters)
Intent myLocalIntent = getIntent();
// grab the data bundle with all the pieces sent to us
// it contains 1. url-address and 2. caption-text
Bundle myBundle = myLocalIntent.getExtras();
urlAddress = myBundle.getString("urlAddress");
urlCaption = myBundle.getString("urlCaption");
System.out.println("urlAddress ####" + urlAddress); // value from
// MainActivity
// http://www.npr.org/rss/rss.php?id=1007
System.out.println("urlCaption####" + urlCaption); // Test RSS
// top caption for this screen
String todayStr = MainActivity.niceDate();
this.setTitle("NPR -" + urlCaption + " \t" + todayStr);
// clicking a line shows more about selected news item
myListView = (ListView) this.findViewById(R.id.myListView);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> _av, View _v, int _index,
long _id) {
// TODO Auto-generated method stub
System.out.println("item click index"+_index);
selectedNewsItem = newsList.get(_index);
showNiceDialogBox(selectedNewsItem, context);
}
});
}// onCreate
@Override
protected void onResume() {
super.onResume();
cNTS = new ConnectToServer(NPRNewsDetails.this,
myListView, newsList);
Log.i("onResum", "I'm Resume");
cNTS.execute(urlAddress);
Log.i("onResum", "I'm Resume");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
}
public void showNiceDialogBox(SingleNewsItem selectedNewsItem,
Context context) {
// assemble a nice looking dialog box
try {
final Uri myLink = Uri.parse(selectedNewsItem.getLink());
AlertDialog.Builder myBuilder = new AlertDialog.Builder(this);
myBuilder
.setIcon(R.drawable.ic_launcher)
.setTitle(urlCaption)
.setMessage(
selectedNewsItem.getTitle() + "\n\n"
+ selectedNewsItem.getDescription() + "\n")
.setPositiveButton("Close", null)
.setNegativeButton("More", new OnClickListener() {
public void onClick(DialogInterface dialog, int whichOne) {
// use native web browsing
Intent webIntent = new Intent(Intent.ACTION_VIEW,
myLink);
startActivity(webIntent);
}
})// setNegativeButton
.create();
myBuilder.show();
} catch (Exception e) {
e.printStackTrace();
}
}// showNiceDialogBox
}
package com.example.testrss;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ConnectToServer extends AsyncTask
{
ListView myListView;
Context context;
ArrayList<SingleNewsItem> newsList = new ArrayList<SingleNewsItem>();
public ConnectToServer(Context context, ListView myListView, ArrayList<SingleNewsItem> newsList)
{
this.context = context;
this.myListView = myListView;
this.newsList.addAll(newsList);
}
@Override
protected Object doInBackground(Object... params)
{
try
{
String urlAddress = (String) params[0];
URL url = new URL(urlAddress);
URLConnection connection;
connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
// NodeListnl= docEle.getElementsByTagName("entry");
NodeList nl = docEle.getElementsByTagName("item");
if ((nl != null) && (nl.getLength() > 0)) {
for (int i = 0; i < nl.getLength(); i++) {
dissectNode(nl, i);
}// for
}// if
}// if
int layoutID = R.layout.my_simple_list_item;
ArrayAdapter<SingleNewsItem> aaNews = new ArrayAdapter<SingleNewsItem>(this.context, layoutID, newsList);
myListView.setAdapter(aaNews);
}
catch (MalformedURLException e) {
System.out.println("Malformed error");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IO error");
e.printStackTrace();
} catch (ParserConfigurationException e) {
System.out.println("Parser error");
e.printStackTrace();
} catch (SAXException e) {
System.out.println("SAX Error");
e.printStackTrace();
}
return null;
}
public void dissectNode(NodeList nl, int i) {
try {
Element entry = (Element) nl.item(i);
Element title = (Element) entry.getElementsByTagName("title").item(
0);
Element description = (Element) entry.getElementsByTagName(
"description").item(0);
Element pubDate = (Element) entry.getElementsByTagName("pubDate")
.item(0);
Element link = (Element) entry.getElementsByTagName("link").item(0);
String titleValue = title.getFirstChild().getNodeValue();
String descriptionValue = description.getFirstChild()
.getNodeValue();
String dateValue = pubDate.getFirstChild().getNodeValue();
String linkValue = link.getFirstChild().getNodeValue();
SingleNewsItem singleItem = new SingleNewsItem(dateValue,
titleValue, descriptionValue, linkValue);
newsList.add(singleItem);
} catch (DOMException e) {
e.printStackTrace();
}
}// dissectNode
@Override
protected void onPostExecute(Object result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
package com.example.testrss;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.HttpURLConnection;
导入java.net.MalformedURLException;
导入java.net.URL;
导入java.net.URLConnection;
导入java.util.ArrayList;
导入javax.xml.parsers.DocumentBuilder;
导入javax.xml.parsers.DocumentBuilderFactory;
导入javax.xml.parsers.parserConfiguration异常;
导入org.w3c.dom.domeException;
导入org.w3c.dom.Document;
导入org.w3c.dom.Element;
导入org.w3c.dom.NodeList;
导入org.xml.sax.SAXException;
导入android.app.Activity;
导入android.app.AlertDialog;
导入android.content.Context;
导入android.content.DialogInterface;
导入android.content.DialogInterface.OnClickListener;
导入android.content.Intent;
导入android.net.Uri;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
导入android.widget.Toast;
公共类NPRNewsDetails扩展活动{
//用户已选择主类别主题
//(数据以捆绑方式发送
//通过main访问web提要并显示相应的标题
ArrayList newsList=新建ArrayList();
ArrayAdapter aa;
列表视图;
字符串url地址=”;
字符串url-caption=“”;
SingleNewsItem selectedNewsItem;
Context=getApplication();
连接到服务器CNT;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListView=(ListView)this.findViewById(R.id.myListView);
//创建本地意图处理程序(需要处理输入参数)
Intent myLocalIntent=getIntent();
//抓取所有发送给我们的数据包
//它包含1.url地址和2.标题文本
Bundle myBundle=myLocalinent.getExtras();
urlAddress=myBundle.getString(“urlAddress”);
urlCaption=myBundle.getString(“urlCaption”);
System.out.println(“urlAddress#####“+urlAddress);//来自
//主要活动
// http://www.npr.org/rss/rss.php?id=1007
System.out.println(“urlCaption######“+urlCaption);//测试RSS
//此屏幕的顶部标题
String todayStr=MainActivity.niceDate();
此.setTitle(“NPR-”+URLCoption+“\t”+todayStr);
//单击一行可显示有关所选新闻项的详细信息
myListView=(ListView)this.findViewById(R.id.myListView);
myListView.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共链接(AdapterView-av、View-v、int-index、,
(长id){
//TODO自动生成的方法存根
System.out.println(“项目点击索引”+_索引);
selectedNewsItem=newsList.get(_index);
显示对话框(选定的新闻项、上下文);
}
});
}//一次创建
@凌驾
受保护的void onResume(){
super.onResume();
cNTS=新的ConnectToServer(NPRNewsDetails.this,
myListView,新闻列表);
Log.i(“onResum”、“我是简历”);
cNTS.execute(URL地址);
Log.i(“onResum”、“我是简历”);
}
@凌驾
受保护的空onDestroy(){
//TODO自动生成的方法存根
}
public void shownice对话框(SingleNewsItem selectedNewsItem,
上下文(上下文){
//组装一个漂亮的对话框
试一试{
最终Uri myLink=Uri.parse(selectedNewsItem.getLink());
AlertDialog.Builder myBuilder=新建AlertDialog.Builder(此);
myBuilder
.setIcon(R.drawable.ic_启动器)
.setTitle(URL标题)
.setMessage(
selectedNewsItem.getTitle()+“\n\n”
+selectedNewsItem.getDescription()+“\n”)
.setPositiveButton(“关闭”,null)
.setNegativeButton(“更多”,新的OnClickListener(){
public void onClick(DialogInterface dialog,int whichOne){
//使用本机web浏览
意向webIntent=新意向(Intent.ACTION\u视图,
myLink);
startActivity(webIntent);
}
})//设置负按钮
.create();
myBuilder.show();
}捕获(例外e){
e、 printStackTrace();
}
}//显示对话框
}
这是ConnectToServer.java代码:
package com.example.testrss;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class NPRNewsDetails extends Activity {
// a main category subject has already been selected by the user
// (data <"urlCaption", "urlAddress"> comes in a bundle sent
// by main, access web-feed and show corresponding headlines
ArrayList<SingleNewsItem> newsList = new ArrayList<SingleNewsItem>();
ArrayAdapter<String> aa;
ListView myListView;
String urlAddress = "";
String urlCaption = "";
SingleNewsItem selectedNewsItem;
Context context = getApplication();
ConnectToServer cNTS;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myListView = (ListView) this.findViewById(R.id.myListView);
// create a local Intent handler (needed to process input parameters)
Intent myLocalIntent = getIntent();
// grab the data bundle with all the pieces sent to us
// it contains 1. url-address and 2. caption-text
Bundle myBundle = myLocalIntent.getExtras();
urlAddress = myBundle.getString("urlAddress");
urlCaption = myBundle.getString("urlCaption");
System.out.println("urlAddress ####" + urlAddress); // value from
// MainActivity
// http://www.npr.org/rss/rss.php?id=1007
System.out.println("urlCaption####" + urlCaption); // Test RSS
// top caption for this screen
String todayStr = MainActivity.niceDate();
this.setTitle("NPR -" + urlCaption + " \t" + todayStr);
// clicking a line shows more about selected news item
myListView = (ListView) this.findViewById(R.id.myListView);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> _av, View _v, int _index,
long _id) {
// TODO Auto-generated method stub
System.out.println("item click index"+_index);
selectedNewsItem = newsList.get(_index);
showNiceDialogBox(selectedNewsItem, context);
}
});
}// onCreate
@Override
protected void onResume() {
super.onResume();
cNTS = new ConnectToServer(NPRNewsDetails.this,
myListView, newsList);
Log.i("onResum", "I'm Resume");
cNTS.execute(urlAddress);
Log.i("onResum", "I'm Resume");
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
}
public void showNiceDialogBox(SingleNewsItem selectedNewsItem,
Context context) {
// assemble a nice looking dialog box
try {
final Uri myLink = Uri.parse(selectedNewsItem.getLink());
AlertDialog.Builder myBuilder = new AlertDialog.Builder(this);
myBuilder
.setIcon(R.drawable.ic_launcher)
.setTitle(urlCaption)
.setMessage(
selectedNewsItem.getTitle() + "\n\n"
+ selectedNewsItem.getDescription() + "\n")
.setPositiveButton("Close", null)
.setNegativeButton("More", new OnClickListener() {
public void onClick(DialogInterface dialog, int whichOne) {
// use native web browsing
Intent webIntent = new Intent(Intent.ACTION_VIEW,
myLink);
startActivity(webIntent);
}
})// setNegativeButton
.create();
myBuilder.show();
} catch (Exception e) {
e.printStackTrace();
}
}// showNiceDialogBox
}
package com.example.testrss;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ConnectToServer extends AsyncTask
{
ListView myListView;
Context context;
ArrayList<SingleNewsItem> newsList = new ArrayList<SingleNewsItem>();
public ConnectToServer(Context context, ListView myListView, ArrayList<SingleNewsItem> newsList)
{
this.context = context;
this.myListView = myListView;
this.newsList.addAll(newsList);
}
@Override
protected Object doInBackground(Object... params)
{
try
{
String urlAddress = (String) params[0];
URL url = new URL(urlAddress);
URLConnection connection;
connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
DocumentBuilderFactory dbf = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(in);
Element docEle = dom.getDocumentElement();
// NodeListnl= docEle.getElementsByTagName("entry");
NodeList nl = docEle.getElementsByTagName("item");
if ((nl != null) && (nl.getLength() > 0)) {
for (int i = 0; i < nl.getLength(); i++) {
dissectNode(nl, i);
}// for
}// if
}// if
int layoutID = R.layout.my_simple_list_item;
ArrayAdapter<SingleNewsItem> aaNews = new ArrayAdapter<SingleNewsItem>(this.context, layoutID, newsList);
myListView.setAdapter(aaNews);
}
catch (MalformedURLException e) {
System.out.println("Malformed error");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IO error");
e.printStackTrace();
} catch (ParserConfigurationException e) {
System.out.println("Parser error");
e.printStackTrace();
} catch (SAXException e) {
System.out.println("SAX Error");
e.printStackTrace();
}
return null;
}
public void dissectNode(NodeList nl, int i) {
try {
Element entry = (Element) nl.item(i);
Element title = (Element) entry.getElementsByTagName("title").item(
0);
Element description = (Element) entry.getElementsByTagName(
"description").item(0);
Element pubDate = (Element) entry.getElementsByTagName("pubDate")
.item(0);
Element link = (Element) entry.getElementsByTagName("link").item(0);
String titleValue = title.getFirstChild().getNodeValue();
String descriptionValue = description.getFirstChild()
.getNodeValue();
String dateValue = pubDate.getFirstChild().getNodeValue();
String linkValue = link.getFirstChild().getNodeValue();
SingleNewsItem singleItem = new SingleNewsItem(dateValue,
titleValue, descriptionValue, linkValue);
newsList.add(singleItem);
} catch (DOMException e) {
e.printStackTrace();
}
}// dissectNode
@Override
protected void onPostExecute(Object result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
package com.example.testrss;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.HttpURLConnection;
导入java.net.MalformedURLException;
导入java.net.URL;
导入java.net.URLConnection;
导入java.util.ArrayList;
导入javax.xml.parsers.DocumentBuilder;
导入javax.xml.parsers.DocumentBuilderFactory;
导入javax.xml.parsers.parserConfiguration异常;
导入javax.xml.parsers.SAXParser;
导入javax.xml.parsers.SAXParserFactory;
导入org.w3c.dom.domeException;
导入org.w3c.dom.Document;
导入org.w3c.dom.Element;
导入org.w3c.dom.NodeList;
导入org.xml.sax.SAXException;
导入org.xml.sax.xml