私はアンドロイドアプリケーションで作業しており、ゲッターとセッターメソッドでエラーが発生しています:
SitesList 型のメソッド setItem(ArrayList) は、引数 (文字列) には適用されません。
私のMyXmlHandlerファイルの行に上記のエラーが表示されます:siteList.setItem(currentValue)
これは私のMyXmlHandlerファイルです:
package com.example.svnitupdates;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class MyXmlHandler extends DefaultHandler {
Boolean currentElement = false;
String currentValue = null;
public static SitesList siteList = null;
public static SitesList getSitesList() {
return siteList;
}
public static void setSitesList(SitesList sitesList) {
MyXmlHandler.siteList = sitesList;
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
if (localName.equals("maintag"))
{
/** Start */
siteList = new SitesList();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
currentElement = false;
/** set value */
if (localName.equalsIgnoreCase("item"))
siteList.setItem(currentValue);
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}
}
}
これは私のSiteList.java です
package com.example.svnitupdates;
import java.util.ArrayList;
import com.example.svnitupdates.R.string;
public class SitesList {
private ArrayList<String> item = new ArrayList<String>();
private ArrayList<String> chapter = new ArrayList<String>();
public ArrayList<String> getItem() {
return item;
}
public void setItem(ArrayList<String> item) {
this.item = item;
}
public ArrayList<String> getChapter() {
return chapter;
}
public void setChapter(ArrayList<String> chapter) {
this.chapter = chapter;
}
}
これは私のUpdatesActivity.java です
package com.example.svnitupdates;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
public class UpdatesActivity extends Activity
{
private ListView listview;
SitesList siteList = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.updates);
listview = (ListView) findViewById(R.id.updatesListView);
final ArrayList<String> list = new ArrayList<String>();
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://localhost/svnit%20updates/updates.xml");
MyXmlHandler myXMLHandler = new MyXmlHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
}catch (Exception e)
{
System.out.println("XML Parsing Excpetion = " + e);
}
siteList = MyXmlHandler.siteList;
for (int i = 0; i < siteList.getItem().size(); ++i)
{
list.add(siteList.getItem.get(i));
}
final UpdatesAdapter adapter = new UpdatesAdapter(UpdatesActivity.this,
android.R.layout.simple_list_item_1, list);
listview.setAdapter(adapter);
listview.setItemsCanFocus(false);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Intent i = new Intent(UpdatesActivity.this, ArticleActivity.class);
i.putExtra("s", position);
startActivity(i);
}
});
}
}
上記のコードではlist.add(siteList.getItem.get(i))
、「.getItem
」の行にエラーが表示され、「フィールドの作成、定数の作成」という修正が表示されます。