xmlデータを取得するためにsaxパーサーを使用しています。以下のコードにより、アプリがクラッシュします。
try {
url = new URL("The URL");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// RssFeed feed = null;
try {
feed = RssReader.read(url);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
でクラッシュしfeed = RssReader.read(url);
ているようです。エボでは正常に動作しますが、ヒーローにインストールすると、以下のエラーが発生します。
04-28 15:57:53.458: E/AndroidRuntime(2749): Uncaught handler: thread main exiting due to uncaught exception
04-28 15:57:53.589: E/AndroidRuntime(2749): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mlgw.mlgwapp/com.mlgw.mlgwapp.TipsActivity}: java.lang.StringIndexOutOfBoundsException
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2411)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:379)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.View.performClick(View.java:2364)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.View.onTouchEvent(View.java:4179)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.View.dispatchTouchEvent(View.java:3709)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.os.Looper.loop(Looper.java:123)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.ActivityThread.main(ActivityThread.java:4595)
04-28 15:57:53.589: E/AndroidRuntime(2749): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-28 15:57:53.589: E/AndroidRuntime(2749): at dalvik.system.NativeStart.main(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749): Caused by: java.lang.StringIndexOutOfBoundsException
04-28 15:57:53.589: E/AndroidRuntime(2749): at java.lang.String.substring(String.java:1646)
04-28 15:57:53.589: E/AndroidRuntime(2749): at nl.matshofman.saxrssreader.RssHandler.endElement(RssHandler.java:67)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:159)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatParser.append(Native Method)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
04-28 15:57:53.589: E/AndroidRuntime(2749): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
04-28 15:57:53.589: E/AndroidRuntime(2749): at nl.matshofman.saxrssreader.RssReader.read(RssReader.java:43)
04-28 15:57:53.589: E/AndroidRuntime(2749): at com.mlgw.mlgwapp.TipsActivity.onCreate(TipsActivity.java:57)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-28 15:57:53.589: E/AndroidRuntime(2749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
助けてください!!
これが私のRssHandlerクラスです
package nl.matshofman.saxrssreader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class RssHandler extends DefaultHandler {
private RssFeed rssFeed;
private RssItem rssItem;
private StringBuilder stringBuilder;
@Override
public void startDocument() {
rssFeed = new RssFeed();
}
/**
* Return the parsed RssFeed with it's RssItems
* @return
*/
public RssFeed getResult() {
return rssFeed;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
stringBuilder = new StringBuilder();
if(qName.equals("item") && rssFeed != null) {
rssItem = new RssItem();
rssItem.setFeed(rssFeed);
rssFeed.addRssItem(rssItem);
}
}
@Override
public void characters(char[] ch, int start, int length) {
stringBuilder.append(ch, start, length);
}
@Override
public void endElement(String uri, String localName, String qName) {
if(rssFeed != null && rssItem == null) {
// Parse feed properties
try {
String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1);
Method method = rssFeed.getClass().getMethod(methodName, String.class);
method.invoke(rssFeed, stringBuilder.toString());
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
} else if (rssItem != null) {
// Parse item properties
try {
if(qName.equals("content:encoded"))
qName = "content";
String methodName = "set" + qName.substring(0, 1).toUpperCase() + qName.substring(1);
Method method = rssItem.getClass().getMethod(methodName, String.class);
method.invoke(rssItem, stringBuilder.toString());
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
}
}わかりました、今これがあると付け加えました
04-28 18:49:35.189: E/AndroidRuntime(3780): Uncaught handler: thread main exiting due to uncaught exception
04-28 18:49:35.328: E/AndroidRuntime(3780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mlgw.mlgwapp/com.mlgw.mlgwapp.TipsActivity}: java.lang.IllegalArgumentException
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2411)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:379)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.View.performClick(View.java:2364)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.View.onTouchEvent(View.java:4179)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.View.dispatchTouchEvent(View.java:3709)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:874)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.view.ViewRoot.handleMessage(ViewRoot.java:1697)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.os.Looper.loop(Looper.java:123)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.ActivityThread.main(ActivityThread.java:4595)
04-28 18:49:35.328: E/AndroidRuntime(3780): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:49:35.328: E/AndroidRuntime(3780): at java.lang.reflect.Method.invoke(Method.java:521)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-28 18:49:35.328: E/AndroidRuntime(3780): at dalvik.system.NativeStart.main(Native Method)
04-28 18:49:35.328: E/AndroidRuntime(3780): Caused by: java.lang.IllegalArgumentException
04-28 18:49:35.328: E/AndroidRuntime(3780): at java.util.Random.nextInt(Random.java:221)
04-28 18:49:35.328: E/AndroidRuntime(3780): at com.mlgw.mlgwapp.TipsActivity.onCreate(TipsActivity.java:71)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-28 18:49:35.328: E/AndroidRuntime(3780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
04-28 18:49:35.328: E/AndroidRuntime(3780): ... 30 more
今、私が使用しているラウンド関数と関係があるようです。