how to determine if a file exists in a directory with FileNotFoundException

by Ohiotech » Tue, 26 Apr 2011 03:33:41 GMT


Sponsored Links
 I've been working with Eclipse ADT for about 2 months. In that time I
have a small utility that allows me to select an IP Address and Port,
and then send a file to that combo. The utility works as intended, but
when I type in the wrong file name, the application hangs.

@Override
   public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }
   }

I've even tried to do the following in hopes that one or the other
would throw, but I am unsuccessful in both.

public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }try {
         throw new Exception("blah blah blah");
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

I've jockeyed around the exception, I've added the one above, I've
tried placing it in different places, and all unsuccessful. Again, I'm
exceptionally new to this, and got here from basically mincing various
tcp client codes. Aside of creating a way to throw the exception
correctly, please help me understand why the first one isn't working
and why the one you suggest is.

-- 



Re: how to determine if a file exists in a directory with FileNotFoundException

by TreKing » Tue, 26 Apr 2011 07:08:32 GMT


 



Pause your debugger to see *where* it's hanging.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Other Threads

1. ListViews getting rendered multiple times

So the situation is this, I have a ListView that is embedded in two
LinearLayout ViewGroups to form a screen. BaseAdapter.getView() (the
implementation of the ListAdapter) is typically called n times (where
n is numElements) to render the screen. The problem I have is this set
of calls is being repeated for every ViewGroup that the list is
contained in...So for a Layout like this:

-LinearLayout
--Linearlayout
---ListView

The adapters getView() is being called n*3 times (3 = 1 for the parent
LinerarLayout, one for the child LinearLayout and one for the List
itself).

This is obvisouly a problem when the items in the List are expensive
to build (even with recycling).

So Im looking for some guidance on this, as the documentation doesnt
seem to note this behaviour from what I can see.

A small, basic example of the source is located on my post here
http://www.anddev.org/listview_getting_rendered_multiple_times-t5290.html
with more details aswel as a ready made eclipse project(also attached
below) if anyone is keen to try it out.

--~--~---------~--~----~------------~-------~--~----~

2. publish error: "The server could not process your apk" when trying to upload

Hi,

trying to upload a new app through the android developer consoleI am
getting the error "The server could not process your apk. Try again".
Searched a bit, found nothing, only unresolved questions.

Any help/hint on what could cause that would be highly appreciated.

Some add. info:
- app runs in the emulator
- exported unsigned
- this is the second app I try to publish, the first is up and running
and selling (well... some... :)
- signed with jarsigner using the same certificate I already used
successfully to publish another app (and as much as I understand the
procedures that should be the right practice)
- when I check it with jarsigner it appears to be ok and signed
- I can push it to the phone and it works there

thx!

--~--~---------~--~----~------------~-------~--~----~

3. Please enable SVG Support in the AndroidWebkit Browser

4. What is the best price to charge for an app?

5. upc lookup...or at least web search?

6. MODIFY_AUDIO_SETTINGS permission

7. Testing a possible localisation issue?