>Well the problem is that iam trying to make somthing happen that iam
>not really understand (iam trying to learn)
>
>So what i wanna do is to "grabb" the "return true" or the "return
>false" so that i could create my if statement.

In that respect - using the static function call to grab the result for an if 
statement - you were using it correctly. 

What you must understand, though, is that in order to get through that static 
method and return an answer to you, it must execute the code within the method. 
That means that you must pass it valid data to work with (or code to *expect* 
null references as an acceptable condition), otherwise at run time it will do 
exactly what it did to you - throw an exception. 

An exception is the Java mechanism for alerting you to the fact that something 
bad happened at run time, and it exits out to the nearest catch handler it can 
as soon as possible - but not exactly gracefully (it may unwind the stack for 
you, but it won't return the value you intended - because code never gets that 
far). If you don’t explicitly add a try / catch block higher up the call chain, 
then your app will die. 

For defending against exceptions you could use a try / catch block around the 
code in your isProInstalled() method - but in your case I advise against that 
for now, as it's likely going to hide a lot of problems you will encounter 
until your understanding improves. 

If your method is asking for a context and trying to use it, ask yourself why 
you are not passing it any valid context. Can you get a valid context to pass 
to it? 

If you *want* to be able to get a quick answer without passing a valid context, 
then you need to code your method to check the context reference before you use 
it - and return an appropriate response if it is null. For example: 

protected static boolean isProInstalled(Context context) {
    if (context == null) 
        return false ; // No valid context - can't tell if it's installed. 
    PackageManager manager = context.getPackageManager();
...

Since your method requires the context to be able to do its job, you need to 
try and get a valid context to pass to the method. 

If you are calling this code somewhere from an Activity, then the activity 
itself is a context you can pass (as ‘this’). 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to