0

I have method that returns string from my DB. My problem is when im trying to use isEmpty() or charAt(0) i get nullPointerException. here is the log cat:

05-09 15:56:47.002: E/AndroidRuntime(6914): FATAL EXCEPTION: main
05-09 15:56:47.002: E/AndroidRuntime(6914): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
05-09 15:56:47.002: E/AndroidRuntime(6914):     at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
05-09 15:56:47.002: E/AndroidRuntime(6914):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4364)
05-09 15:56:47.002: E/AndroidRuntime(6914):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
05-09 15:56:47.002: E/AndroidRuntime(6914):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)

   public boolean setTheCorrectParameterFields(){

            String mine = "";

            String spinnerExercise = workOutChoose.getSelectedItem().toString();
            DataBaseMain fieldsNum = new DataBaseMain(getApplicationContext());
            fieldsNum.open();
            mine = fieldsNum.getParameters(spinnerExercise);
            fieldsNum.close();

            if(mine.isEmpty())
                return false;
            return true;
            }
1
  • IF that's the line its crashing at, then getParameters is returning null. Can't help more because we don't have the code for that class. Commented May 9, 2013 at 16:09

3 Answers 3

1

mine is null on return from fieldsNum.getParameters(spinnerExercise). You need to check for a non-null value before trying to do other things with it.

Sign up to request clarification or add additional context in comments.

Comments

0

There's a method which allows you to do a null-safe empty check on a String in Commons Lang 3.

http://commons.apache.org/proper/commons-lang//apidocs/org/apache/commons/lang3/StringUtils.html#isEmpty(java.lang.CharSequence)

1 Comment

Oh why Commons? There is an equivalent in Android SDK, developer.android.com/reference/android/text/…
0

Because isEmpty is a method on a null object, you can not call it. You should try this instead:

  boolean empty = mine == null || mine.isEmpty() ? true : false;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.