×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    J2ME Null Exception while downloadin large files

    Hello Everyone,

    I am developing an app in which files (mp3 files) are downloaded from URL, Songs are downloaded properly, but I am facing following random issue.
    Sometimes while songs are downloading inputstream.read() returns -1 i.e. null even when songs are not completely downloaded .. So I cannot proceed further towards listening that song. Please help me.

    Thanks in Advance.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: J2ME Null Exception while downloadin large files

    Your thread is moved to the "Mobile Java General" board now. For future reference: you can easily find the Java boards from the discussion "root" http://www.developer.nokia.com/Commu...sion/forum.php, as part of Development Platforms.

  3. #3
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: J2ME Null Exception while downloadin large files

    You need to provide more information.
    Like what are the sizes of the files you successfully download and what are the sizes of files which you cannot download (maybe the files are just too big)? What device are you using? Are the failures dependent of the number of downloads you have done during the same session (could be a memory management issue). Etc.

    Hartti

  4. #4
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    @hartti - Thanks for your reply, as I mentioned earlier its a random issue, means sometimes 35 mb file is downloaded properly & sometimes even 5 mb file is not downloaded. I am downloading files in chunks of 512 or 1024 bytes. I am using Nokia series S40 (6260) simulator & Nokia E-50 real device, & the problem arises on both. I have debugged my code & finally I have come to know that while songs are downloading as input stream reads -1 even if end of song is not reached.

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: J2ME Null Exception while downloadin large files

    try to put is. Available() before reading the stream - this can help you avoid -1 before the actual end of the stream.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  6. #6
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    @ Amit Sir - I had tried this too, but it doesn't work at all, after lot of trying I have read the API for input stream from oracle website & here is the statement from them - ("The available method for class Input Stream always returns 0."), & its true, it always returns 0. I am using HTTP Connection & Input Stream for reading mp3 files then store in in buffer of size 1024 bytes. then write it into file using file connection & Data Output Stream, I have problem while reading the mp3 files.

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: J2ME Null Exception while downloadin large files

    Quote Originally Posted by vishal.vpb View Post
    @ Amit Sir - I had tried this too, but it doesn't work at all, after lot of trying I have read the API for input stream from oracle website & here is the statement from them - ("The available method for class Input Stream always returns 0."), & its true, it always returns 0. I am using HTTP Connection & Input Stream for reading mp3 files then store in in buffer of size 1024 bytes. then write it into file using file connection & Data Output Stream, I have problem while reading the mp3 files.
    Just for test - try to pass the IS directly to the player manager and play to see - if it is able to get the full MP3 on the device & Play. check progressive download for S40 also.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  8. #8
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    Is there any way by which I can download files (mp3) by just providing URL's & rest of downloading is performed by Mobile Browser itself... Means I don't need to write code for downloading (its easy but not working for me)....Cause songs are properly downloaded if I download them by using Mobile Browser, but downloading fails if I use my J2ME app.

  9. #9
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: J2ME Null Exception while downloadin large files

    Have you tested PlatformRequest() - would that be good enough for you?

    Hartti

  10. #10
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    @hartti - Thanks... Songs are now properly downloading using platformRequest() , but I don't want to share my links (url's) with others, whenever platformrequest() invokes it prompt for user with message containing URL, also i don't want to pause my midlet while downloading. I have no option left other than downloading songs using http connection & input stream(), Is there any problem with encoding of mp3 files or httprequest() method, please help me.

  11. #11
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    Thank you everyone for your valuable help. Have just come to know why the "great null exception" occurs while downloading files. My code was absolutely perfect, but am accessing web via wi-fi, which (wi-fi) got automatically disconnected after some random time span, so when (faulty) wi-fi connection got disconnected input stream returns null, & hence exception occur.

  12. #12
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: J2ME Null Exception while downloadin large files

    Especially on a S40 device downloading a 35 megs file will be pretty tough..
    For example that 6260 you are mentioning has just 4 MB of heap size : http://www.developer.nokia.com/Devic...ns/6260_slide/
    That means thats the max memory your application will receive to work with, so if you are trying to keep a 35 megs file in-memory it will simply throw an OutOfMemoryException at some point...
    Maybe you should extensively try files under 4 megs
    Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them.

  13. #13
    Registered User
    Join Date
    Jun 2011
    Location
    Nasik India
    Posts
    39

    Re: J2ME Null Exception while downloadin large files

    Quote Originally Posted by Tiger79 View Post
    Maybe you should extensively try files under 4 megs
    Yes downloading larger files causes "OutOfMemoryException", to avoid this am downloading larger files in chunks which works fine.

Similar Threads

  1. Null pointer exception
    By clydening in forum Mobile Java General
    Replies: 3
    Last Post: 2010-04-19, 08:42
  2. null pointer exception
    By Arunesh in forum Mobile Java General
    Replies: 6
    Last Post: 2010-01-15, 12:38
  3. Null Pointer Exception!
    By Eric Ma in forum Mobile Java General
    Replies: 16
    Last Post: 2009-03-10, 10:51
  4. USER 44 while reading large files
    By sajain in forum Symbian
    Replies: 3
    Last Post: 2008-02-05, 11:12
  5. Null Pointer exception while using custom class
    By kamalesh in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2004-04-02, 13:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×