Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android无法解析菜单项_Android_Xml_Xml Parsing_Sax - Fatal编程技术网

Android无法解析菜单项

Android无法解析菜单项,android,xml,xml-parsing,sax,Android,Xml,Xml Parsing,Sax,我正在为Android开发RSS阅读器,在添加菜单项时遇到了一个问题。我想创建一个项目来手动刷新提要,但出现错误“Menu.item无法解析为类型”。错误在这里: public boolean onOptionsItemSelected(Menu.Item item){ switch (item.getId()) { case 0: Log.i(tag,"Set RSS Feed"); return true; case 1:

我正在为Android开发RSS阅读器,在添加菜单项时遇到了一个问题。我想创建一个项目来手动刷新提要,但出现错误“Menu.item无法解析为类型”。错误在这里:

public boolean onOptionsItemSelected(Menu.Item item){
    switch (item.getId()) {
    case 0:

        Log.i(tag,"Set RSS Feed");
        return true;
    case 1:
        Log.i(tag,"Refreshing RSS Feed");
        return true;
    }
    return false;
}
全班同学在这里:

package com.CalvaryChapelMelbourne.feedparser;


import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener; 
import android.util.Log;
import java.util.ArrayList;
import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;

import org.xml.sax.XMLReader;

import android.content.Intent;

import com.CalvaryChapelMelbourne.feedparser.ShowDescription;

public class RSSReader extends Activity implements OnItemClickListener
{

public final String RSSFEEDOFCHOICE = "http://app.calvaryccm.com/mobile/android/v1/devos";

public final String tag = "RSSReader";
private RSSFeed feed = null;

/** Called when the activity is first created. */

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    // go get our feed!
    feed = getFeed(RSSFEEDOFCHOICE);

    // display UI
    UpdateDisplay();

}


private RSSFeed getFeed(String urlToRssFeed)
{
    try
    {
        // setup the url
       URL url = new URL(urlToRssFeed);

       // create the factory
       SAXParserFactory factory = SAXParserFactory.newInstance();
       // create a parser
       SAXParser parser = factory.newSAXParser();

       // create the reader (scanner)
       XMLReader xmlreader = parser.getXMLReader();
       // instantiate our handler
       RSSHandler theRssHandler = new RSSHandler();
       // assign our handler
       xmlreader.setContentHandler(theRssHandler);
       // get our data via the url class
       InputSource is = new InputSource(url.openStream());
       // perform the synchronous parse           
       xmlreader.parse(is);
       // get the results - should be a fully populated RSSFeed instance, or null on error
       return theRssHandler.getFeed();
    }
    catch (Exception ee)
    {
        // if we have a problem, simply return null
        return null;
    }
}
public boolean onCreateOptionsMenu(Menu menu) 
{
    super.onCreateOptionsMenu(menu);

    menu.add(0,0,"Choose RSS Feed");
    menu.add(0,1,"Refresh");
    Log.i(tag,"onCreateOptionsMenu");
    return true;
}

public boolean onOptionsItemSelected(Menu.Item item){
    switch (item.getId()) {
    case 0:

        Log.i(tag,"Set RSS Feed");
        return true;
    case 1:
        Log.i(tag,"Refreshing RSS Feed");
        return true;
    }
    return false;
}


private void UpdateDisplay()
{
    TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
    TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
    ListView itemlist = (ListView) findViewById(R.id.itemlist);


    if (feed == null)
    {
        feedtitle.setText("No RSS Feed Available");
        return;
    }

    feedtitle.setText(feed.getTitle());
    feedpubdate.setText(feed.getPubDate());

    ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());

    itemlist.setAdapter(adapter);

    itemlist.setOnItemClickListener(this);

    itemlist.setSelection(0);

}


 public void onItemClick(AdapterView parent, View v, int position, long id)
 {
     Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");

     Intent itemintent = new Intent(this,ShowDescription.class);

     Bundle b = new Bundle();
     b.putString("title", feed.getItem(position).getTitle());
     b.putString("description", feed.getItem(position).getDescription());
     b.putString("link", feed.getItem(position).getLink());
     b.putString("pubdate", feed.getItem(position).getPubDate());

     itemintent.putExtra("android.intent.extra.INTENT", b);

     startSubActivity(itemintent,0);
 }

}
package com.CalvaryChapelMelbourne.feedparser;
导入android.app.Activity;
导入android.os.Bundle;
导入android.view.*;
导入android.widget.TextView;
导入android.widget.ListView;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ArrayAdapter;
导入android.widget.AdapterView.OnItemClickListener;
导入android.util.Log;
导入java.util.ArrayList;
导入java.net.URL;
导入javax.xml.parsers.SAXParser;
导入javax.xml.parsers.SAXParserFactory;
导入org.xml.sax.InputSource;
导入org.xml.sax.XMLReader;
导入android.content.Intent;
导入com.CalvaryChapelMelbourne.feedparser.ShowDescription;
公共类RSSReader扩展活动实现了MClickListener
{
公共最终字符串RSSFEEDOFCHOICE=”http://app.calvaryccm.com/mobile/android/v1/devos";
公共最终字符串tag=“RSSReader”;
专用RSSFeed feed=null;
/**在首次创建活动时调用*/
创建公共空间(捆绑冰柱){
超级冰柱;
setContentView(R.layout.main);
//去拿我们的饲料!
feed=getFeed(rssfeedof选择);
//显示用户界面
UpdateDisplay();
}
私有RSSFeed getFeed(字符串urlToRssFeed)
{
尝试
{
//设置url
URL=新URL(urlToRssFeed);
//创建工厂
SAXParserFactory=SAXParserFactory.newInstance();
//创建解析器
SAXParser parser=factory.newSAXParser();
//创建读卡器(扫描仪)
XMLReader=parser.getXMLReader();
//实例化我们的处理程序
RSSHandler-theRssHandler=新的RSSHandler();
//指派我们的处理人
setContentHandler(ThersHandler);
//通过url类获取我们的数据
InputSource is=新的InputSource(url.openStream());
//执行同步解析
parse(is);
//获取结果-应为完全填充的RSSFeed实例,或错误时为null
返回theRssHandler.getFeed();
}
捕获(异常ee)
{
//如果有问题,只需返回null
返回null;
}
}
公共布尔onCreateOptions菜单(菜单)
{
super.onCreateOptions菜单(菜单);
添加(0,0,“选择RSS提要”);
菜单。添加(0,1,“刷新”);
Log.i(标记“onCreateOptions菜单”);
返回true;
}
公共布尔值onOptionsItemSelected(Menu.Item){
开关(item.getId()){
案例0:
Log.i(标签,“设置RSS提要”);
返回true;
案例1:
Log.i(标签,“刷新RSS提要”);
返回true;
}
返回false;
}
私有void UpdateDisplay()
{
TextView feedtitle=(TextView)findViewById(R.id.feedtitle);
TextView feedpubdate=(TextView)findViewById(R.id.feedpubdate);
ListView itemlist=(ListView)findViewById(R.id.itemlist);
if(feed==null)
{
feedtitle.setText(“没有可用的RSS源”);
返回;
}
feedtitle.setText(feed.getTitle());
feedpubdate.setText(feed.getPubDate());
ArrayAdapter=newArrayAdapter(这是android.R.layout.simple_list_item_1,feed.getAllItems());
itemlist.setAdapter(适配器);
itemlist.setOnItemClickListener(此);
itemlist.setSelection(0);
}
public void onItemClick(AdapterView父视图、视图v、整型位置、长id)
{
Log.i(标记“单击的项”[“+feed.getItem(position.getTitle()+”]);
Intent itemintent=新的Intent(这个,showsdescription.class);
Bundle b=新Bundle();
b、 putString(“title”,feed.getItem(position.getTitle());
b、 putString(“description”,feed.getItem(position.getDescription());
b、 putString(“link”,feed.getItem(position.getLink());
b、 putString(“pubdate”,feed.getItem(position.getPubDate());
itemintent.putExtra(“android.intent.extra.intent”,b);
startSubActivity(itemintent,0);
}
}

谢谢你的帮助

它应该是
MenuItem
,而不是
菜单项

public boolean onOptionsItemSelected(MenuItem item){

您需要将菜单项更改为菜单项,而不是菜单项。只需删除点,你应该很好去