My Android-App crashes when it's coming to read a XML File

Go To StackoverFlow.com

0

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)
2012-04-04 19:05
by NoName
edit other code with this lin - ρяσѕρєя K 2012-04-04 19:12
u got solution or not - ρяσѕρєя K 2012-04-04 19:25
We can't really help unless you can give us more information. What does "crash" mean? Is there logcat output for the exception? Show us the broader context for the issue (i.e., code before/after this line) - Jon O 2012-04-04 19:27
@JonO, from the LogCat: "Can't load screen layout, ERROR: java.lang.NullPointerException";

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

Thanks for the additional info. Please edit your question with the full stack trace from LogCat. It contains line-number information that will help us debug. Please also include the code for the method that crashes, if you can - Jon O 2012-04-05 14:36
@JonO, i have uploaded it to http://pastebin.com/mdRDWsK2 check it out..

I used the XmlPullParserFactory class for this mission. which part of the code you need - NoName 2012-04-05 16:50

Is your code catching and logging this NullPointerException? If so, it would help for you to make a change to let ListView throw the exception so the whole stack trace can be output in LogCat. Alternately, use Log.e(tag,message,exception) - Jon O 2012-04-06 16:15
post the line declaring the listview and related xml.. - Rahul garg 2012-04-06 16:41
@JonO I put the code that you gave me and all the output that I got from the $Log.e i put in the General Massage (up there ^^)

you know what is the problem - NoName 2012-04-07 13:18

Your error is in 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
@JonO I add onCreate method to the post. - NoName 2012-04-09 17:14
And line 130 is if (eventType == XmlPullParser.START_TAG)? Where do you get eventType from - Jon O 2012-04-09 17:20
@JonO I did not notice that I gave the line.. 130 Line is

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



0

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 Strings. Where is mStrings initialized?

2012-04-10 13:44
by Jon O
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

That's why you are getting the 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

On the same line - Jon O 2012-04-12 20:39
I put the new errors in the post.. Line 128 it's the mStrings [_0xFa]NoName 2012-04-13 09:59
This is a different error. It's an AIOOBE. _0xFa is bigger than 249 - Jon O 2012-04-13 14:31
Ok.. so I am decide to use an array list for this because i don't know what is the length.

I put the new errors in the post - NoName 2012-04-13 20:26

You don't have enough memory to put all of that stuff in a list. Whatever you're doing with it, you need to change your approach since you don't have memory for a list that big - Jon O 2012-04-14 14:03
Ads