Returning a method

I have a method that returns true or false

String projDest = null;

public boolean projDestCheck() {
      projDest = EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();
     
      if (projDest.equals("MATRIX_ONE")){
          return false;
      }
      else {
         return true;
      }
  }

Open in new window


The problem I am having is the method can run before there is a value for
 projDest = EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();

So I am getting null pointer error.  How do I fix that method so that if there is not a value for projDest, it does not throw a null pointer and sets the method to true
jkteaterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
Check if projDest == null befoire you do anuy orher checks and return nill befiore yoiu go to anyhtinhg ese
0
jkteaterAuthor Commented:
Like this?

If (projDest == null) {
     return true;
}
else {
      
projDest = EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();
     
      if (projDest.equals("MATRIX_ONE")){
          return false;
      }
      else {
         return true;
      }
}

Open in new window

0
for_yanCommented:
No.
Like this :

public boolean projDestCheck() {
      projDest = EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();
     if(projDest == null) return true;
      if (projDest.equals("MATRIX_ONE")){
          return false;
      }
      else {
         return true;
      }
  }
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

jkteaterAuthor Commented:
The problem is that the assignment

 projDest = EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();

will cause a null pointer, because until the user selects a project this is not a valid call

 EdiSystemData.getDestinationPrefix(currentProject.getDestinationPrefixId()).getName();

but once the user selects a project it is fine.  

I am calling that method before the user can assign a project.  If you see the other questions - it explains why
0
for_yanCommented:
Then before this call put such line:

If(currentProject == null) return true;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkteaterAuthor Commented:
nice catch
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.