I built an application whose function is to receive RSS updates to the device and show as output. The problem is that the app crashes every time when it begins to read the file ..
BTW, the file comes from a website.
if (eventType == XmlPullParser.START_TAG)
it's crashes when it comes to this row... anybody idea?
Here is the LogCat output:
04-05 16:47:47.320: D/dalvikvm(352): GC_EXTERNAL_ALLOC freed 47K, 53% free 2547K/5379K, external 1957K/2137K, paused 144ms
04-05 16:47:47.917: D/dalvikvm(352): GC_EXTERNAL_ALLOC freed 1K, 53% free 2547K/5379K, external 2160K/2512K, paused 299ms
04-05 16:47:54.328: E/global(352): Deprecated Thread methods are not supported.
04-05 16:47:54.328: E/global(352): java.lang.UnsupportedOperationException
04-05 16:47:54.328: E/global(352): at java.lang.VMThread.stop(VMThread.java:85)
04-05 16:47:54.328: E/global(352): at java.lang.Thread.stop(Thread.java:1280)
04-05 16:47:54.328: E/global(352): at java.lang.Thread.stop(Thread.java:1247)
04-05 16:47:54.328: E/global(352): at dc.myappdsdasdadasda.app.___Startupseeds___$1.run(___Startupseeds___.java:54)
04-05 16:47:54.718: I/myappdsdasdadasda ListView loading..(352): ========================= [STARTER] ==========================
04-05 16:47:55.067: D/dalvikvm(352): GC_EXTERNAL_ALLOC freed 15K, 53% free 2567K/5379K, external 2736K/2946K, paused 207ms
04-05 16:47:55.479: I/myappdsdasdadasda ListView loading(352): URL ... {patch/xml}
04-05 16:47:55.497: I/myappdsdasdadasda ListView loading(352): Setting namespace.
04-05 16:47:55.497: I/myappdsdasdadasda ListView loading(352): xpp factory loaded
04-05 16:47:55.508: I/myappdsdasdadasda ListView loading(352): settingup utf-8 enccoding
04-05 16:47:57.389: I/myappdsdasdadasda ListView loading(352): AB AC AS HS[10] 001101 QTcheck #1
04-05 16:47:57.389: I/myappdsdasdadasda ListView loading(352): AB AC AS HS[10] 001101 QTcheck #2
04-05 16:47:57.389: I/myappdsdasdadasda ListView loading(352): AB AC AS HS[10] 001101 QTcheck #3
04-05 16:47:57.469: E/myappdsdasdadasda ListView loading..(352): Can't load screen layout, ERROR: java.lang.NullPointerException
04-05 16:47:57.469: I/myappdsdasdadasda ListView loaded(352): ========================= [FAILED!] ==========================
04-05 16:47:58.147: D/dalvikvm(352): GC_EXTERNAL_ALLOC freed 65K, 52% free 2599K/5379K, external 3221K/3471K, paused 68ms
04-05 16:47:58.329: D/dalvikvm(352): GC_EXTERNAL_ALLOC freed <1K, 52% free 2598K/5379K, external 4627K/5778K, paused 79ms
The Null Pointer Exception:
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): Can't load screen layout, ERROR:
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): java.lang.NullPointerException
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at dc.suUSDAKDAL.app._0xSession.onCreate(_0xSession.java:130)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.os.Looper.loop(Looper.java:123)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at java.lang.reflect.Method.invokeNative(Native Method)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at java.lang.reflect.Method.invoke(Method.java:507)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-07 13:05:44.373: E/suUSDAKDAL ListView loading..(351): at dalvik.system.NativeStart.main(Native Method)
OnCreate:
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_TAG)
{
if (xpp.getName().equalsIgnoreCase("item"))
{
insideItem = true;
}
else if (xpp.getName().equalsIgnoreCase("title"))
{
if (insideItem)
_viTitle[_0xFa] = xpp.nextText();
}
else if (xpp.getName().equalsIgnoreCase("description"))
{
if (insideItem)
vi_subTitle[_0xFa] = xpp.nextText();
}
else if (xpp.getName().equalsIgnoreCase("link"))
{
if (insideItem)
__Links[_0xFa] = xpp.nextText();
}
}
else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item"))
{
insideItem=false;
}
mStrings [_0xFa] = "http://images3.wikia.nocookie.net/__cb20111202150846/theamazingworldofgumball/images/c/c1/Banana_joe_on_the_floor,lol!.png";
_0xFa ++;
}
New error:
04-13 09:48:53.999: E/AndroidRuntime(336): FATAL EXCEPTION: main
04-13 09:48:53.999: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{dc.sus.app/dc.sus.app._0xSession}: java.lang.ArrayIndexOutOfBoundsException
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.os.Looper.loop(Looper.java:123)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-13 09:48:53.999: E/AndroidRuntime(336): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 09:48:53.999: E/AndroidRuntime(336): at java.lang.reflect.Method.invoke(Method.java:507)
04-13 09:48:53.999: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-13 09:48:53.999: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-13 09:48:53.999: E/AndroidRuntime(336): at dalvik.system.NativeStart.main(Native Method)
04-13 09:48:53.999: E/AndroidRuntime(336): Caused by: java.lang.ArrayIndexOutOfBoundsException
04-13 09:48:53.999: E/AndroidRuntime(336): at dc.sus.app._0xSession.onCreate(_0xSession.java:128)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-13 09:48:53.999: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-13 09:48:53.999: E/AndroidRuntime(336): ... 11 more
New stack trace:
04-13 20:22:17.634: E/AndroidRuntime(527): FATAL EXCEPTION: main
04-13 20:22:17.634: E/AndroidRuntime(527): java.lang.OutOfMemoryError
04-13 20:22:17.634: E/AndroidRuntime(527): at java.util.ArrayList.add(ArrayList.java:123)
04-13 20:22:17.634: E/AndroidRuntime(527): at dc.sus.app._0xSession.onCreate(_0xSession.java:127)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.os.Looper.loop(Looper.java:123)
04-13 20:22:17.634: E/AndroidRuntime(527): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-13 20:22:17.634: E/AndroidRuntime(527): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 20:22:17.634: E/AndroidRuntime(527): at java.lang.reflect.Method.invoke(Method.java:507)
04-13 20:22:17.634: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-13 20:22:17.634: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-13 20:22:17.634: E/AndroidRuntime(527): at dalvik.system.NativeStart.main(Native Method)
At the beginning of the code i am using a while loop to read all tags in the file. - NoName 2012-04-04 21:02
I used the XmlPullParserFactory class for this mission. which part of the code you need - NoName 2012-04-05 16:50
Log.e(tag,message,exception)
- Jon O 2012-04-06 16:15
you know what is the problem - NoName 2012-04-07 13:18
onCreate
at line 130. Can you add your onCreate
method (and any related class member variable declarations/initializations) into your post, and indicate which line is throwing the error - Jon O 2012-04-09 14:06
if (eventType == XmlPullParser.START_TAG)
? Where do you get eventType
from - Jon O 2012-04-09 17:20
mStrings [_0xFa] = "http://images3.wikia.nocookie.net/__cb20111202150846/theamazingworldofgumball/images/c/c1/Banana_joe_on_the_floor,lol!.png";
eventType i got from int eventType = xpp.getEventType();
it's above the while loop. - NoName 2012-04-09 20:39
Moving from the comment thread to an answer... You're getting a null pointer exception when the code tries to dereference mStrings[_0xFa]
. I imagine mStrings
is an array of String
s. Where is mStrings
initialized?
public void onCreate(Bundle savedInstanceState)
{
String[] mStrings = null;
String[] _viTitle = null;
String[] vi_subTitle = null;
String[] __Links = null;
at the beginning of the method OnCreat - NoName 2012-04-10 19:38
NullPointerException
. mStrings
is null
, so when you try to set mStrings[x]
there's nothing for it to index into. You need to initialize this (and likely the other arrays) things using String[] mStrings = new String[length];
. Or if you don't know how long it will be, use an ArrayList<String>
instead and call list.add(item)
when you want to add something - Jon O 2012-04-11 14:49
String[] mStrings = new String[250];
String[] _viTitle = new String[250];
String[] vi_subTitle = new String[250];
String[] __Links = new String[250];
Still .. I get the same errorsNoName 2012-04-12 19:16
mStrings [_0xFa]
NoName 2012-04-13 09:59
I put the new errors in the post - NoName 2012-04-13 20:26