Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

New Forums: Nexus Player | Nexus 9
test: Reply
 
LinkBack Thread Tools
Old January 13th, 2011, 07:27 AM   #1 (permalink)
cul
New Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Cry Download Zip to SD card, zip not getting readů

hello there, tried following code to download zip to sd card, i get NullpointerException. when tried some interrogations i come to know that the zip file is not getting downloaded actually. So would you please help whether code needs some changes or anything wrong with zip? M stuck on that point only. Please help... my code as follows... help appreciated...

Code:
  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String from = "http://192.168.1.63/ZipFile/Text.zip" ;
        String to = Environment.getExternalStorageDirectory() + "/newunzip/";
        
        try {
            ((TextView) findViewById(R.id.display)).append("\n in try after function :");
            downloadFile(from, to);
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            ((TextView) findViewById(R.id.display)).append("\n \n Exception occured :");
            ((TextView) findViewById(R.id.display)).append("\n \n Exception message is :"+e.getMessage());
            ((TextView) findViewById(R.id.display)).append("\n \n Exception is :"+e.toString());
        }
        
    }
    
    private void downloadFile(String from, String to) throws Exception 
    {
        ((TextView) findViewById(R.id.display)).append("\n \n in function call :");
        HttpURLConnection conn = (HttpURLConnection)new URL(from).openConnection();
        conn.setDoInput(true);
        conn.setConnectTimeout(100000); // timeout 100 secs
        conn.connect();
        
        ((TextView) findViewById(R.id.display)).append("\n \n Connecting to url :"+ conn);
        InputStream input = conn.getInputStream();
        
        byte[] b = null;
        input.read(b);
        ((TextView) findViewById(R.id.display)).append("\n \n input method :"+ b);
        
        FileOutputStream fOut = new FileOutputStream(to);
        
        byte[] b1 = null;
        input.read(b1);
        ((TextView) findViewById(R.id.display)).append("\n \n output method :"+ b1);
        
        int byteCount = 0;
        byte[] buffer = new byte[4096];
        int bytesRead = -1;
        while ((bytesRead = input.read(buffer)) != -1) 
        {
            ((TextView) findViewById(R.id.display)).append("\n \n reading/writing files :");
            fOut.write(buffer, 0, bytesRead);
            byteCount += bytesRead;
        }
        fOut.flush();
        ((TextView) findViewById(R.id.display)).append("\n \n flush & close :");
        fOut.close();
    }

}

Advertisements
cul is offline  
Reply With Quote
sponsored links
Old January 14th, 2011, 07:22 AM   #2 (permalink)
cul
New Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

answer plzzzzzzzz..........
cul is offline  
Reply With Quote
Old January 14th, 2011, 08:33 AM   #3 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 313
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 53 Times in 51 Posts
Default

Post the excpetion your getting in logcat here. This will make it much easier for us to help you.
miXer is offline  
Reply With Quote
Old January 15th, 2011, 01:11 AM   #4 (permalink)
cul
New Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

it givin null pointer exception
cul is offline  
Reply With Quote
Old January 15th, 2011, 01:50 AM   #5 (permalink)
Junior Member
 
DylanTimby's Avatar
 
Join Date: Jan 2011
Location: Sunderland, United Kingdom
Posts: 36
 
Device(s): T-Mobile Mini Pulse(Rooted)
Carrier: Not Provided

Thanks: 1
Thanked 5 Times in 5 Posts
Send a message via MSN to DylanTimby Send a message via Skype™ to DylanTimby dylanrootz@googlemail.com
Default

Hello there, due to the point at Android OS is based on Linux .zip files are not supported, but I am sure .rar is , Feel free to PM me if you need anymore help.




Thanks,
Dylan
__________________
-If you need any help, PM me!
-PHP/MySQL Developer...
CHEAP Website Hosting!
DylanTimby is offline  
Reply With Quote
Old January 15th, 2011, 05:02 AM   #6 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 313
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 53 Times in 51 Posts
Default

Quote:
Originally Posted by cul View Post
it givin null pointer exception
Yes, i know that. But the full exception includes which line number and stuff the exception occured on.
miXer is offline  
Reply With Quote
Old January 15th, 2011, 05:04 AM   #7 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 313
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 53 Times in 51 Posts
Default

Quote:
Originally Posted by DylanTimby View Post
Hello there, due to the point at Android OS is based on Linux .zip files are not supported, but I am sure .rar is , Feel free to PM me if you need anymore help.




Thanks,
Dylan
Android has this package included from java. That would mean android should support it?

java.util.zip | Android Developers
miXer is offline  
Reply With Quote
Old January 17th, 2011, 01:13 AM   #8 (permalink)
cul
New Member
Thread Author (OP)
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK thanx for your reply guys! first of all .zip is not getting downloaded which i resolved with using "astro" in which I've given permission to download all files.

But after that it's not going to download that file instead it giving null pointer exception... n no other message it's generating. only null pointer exception, m stuck here badly.. plz help me out!
cul is offline  
Reply With Quote
Reply
Tags
android, developer, downlaod, java, sd-card, web service, zip


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:08 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.