Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:44+00:00 2026-06-11T12:32:44+00:00

Been going crazy with ANDROID’s regex using the pattern / matcher methods. I’ve been

  • 0

Been going crazy with ANDROID’s regex using the pattern / matcher methods. I’ve been pretty unsuccessful for several days now. And yes I have been searching SO for help prior to asking for direct help. Ok, here’s the deal: my incoming stream looks like this

Time in UTC (HhMmSs): 154653
Status (A=OK,V=KO): V
Latitude: 4428.2011
Direction (N/S): N

Longitude: 00440.5161

Direction (E/W): W

Speed in knots: 000.5

Direction in degrees: 342.8

Date in UTC (DdMmAa): 050407

Magnetic variation:

Variation (E/W):

Mode: A

All I want for now is the Latitude and Longitude values.

My code looks like this:

public class NmeaParser {
/**
 * Tag used for log messages
 */
public String nmeaData;
public String lat; //latitude
public String lon; //longitude

private static final String LOG_TAG = "NPGPS";



public String longitude, latitude;
//find the text pattern
public static final Pattern NMEA_PATTERN = Pattern.
            compile(
                    "\\d{6}" +
                    ":\\s\\D" +
                    "\\w+\\S\\s\\d{4}.\\d+" +
                    ":\\s\\D" +
                    "\\w+\\S\\s\\d{5}.\\d+" +
                    ":\\s\\D" +
                    "\\d{3}.\\d{1}" +
                    "\\d{3}.\\d{1}" +
                    "\\d{6}" +
                    ":\\s\\D" +
                    ":\\s\\D"
                    //".*" //this works as a test
                    );

public String parseNmeaSentence(String gpsSentence) {
        Matcher rmcMatcher = NMEA_PATTERN.matcher(gpsSentence);
        //Log.i(LOG_TAG, "dataNP: "+ rmcMatcher);
        if (rmcMatcher.find()) {
                //Log.d("Matcher", "PATTERN MATCHES!");
            //else
                //Log.d("MATCHER", "PATTERN DOES NOT MATCH!");
            //String time = rmcMatcher.group(1);
          latitude = rmcMatcher.group(3);
          nmeaData = latitude;

        }
            return nmeaData;
  }
}

and I keep getting these errors:

09-17 11:37:36.936: E/AndroidRuntime(8756): FATAL EXCEPTION: main
09-17 11:37:36.936: E/AndroidRuntime(8756): java.lang.NullPointerException
09-17 11:37:36.936: E/AndroidRuntime(8756):     at                 android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.AbsListView.obtainView(AbsListView.java:2058)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.ListView.onMeasure(ListView.java:1155)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.View.measure(View.java:12723)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.View.measure(View.java:12723)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.View.measure(View.java:12723)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.View.measure(View.java:12723)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.View.measure(View.java:12723)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.os.Looper.loop(Looper.java:137)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at android.app.ActivityThread.main(ActivityThread.java:4575)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at java.lang.reflect.Method.invokeNative(Native Method)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at java.lang.reflect.Method.invoke(Method.java:511)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-17 11:37:36.936: E/AndroidRuntime(8756):     at dalvik.system.NativeStart.main(Native Method)

Clearly I’m screwing up with my regex syntax within the pattern / matcher methods.
Any help is clearly appreciated.
thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:32:46+00:00Added an answer on June 11, 2026 at 12:32 pm

    From your trace it appears that android.widget.ArrayAdapter is missing a resource in your code so this is the real issue why you can’t proceed.

    Re your regex, you don’t have any capturing groups in your regular expression and your pattern doesn’t match your input string.

    The best approach when using many expressions is to match up 1 or 2 expressions at a time to get those working first.

    As you only wanted latitude & longitude, here is that regex code to get you (re-)started:

    Pattern NMEA_PATTERN = Pattern.compile(
                    ".*Latitude: (\\d{4}.\\d+).*" + 
                    "Longitude: (\\d{5}.\\d+).*");
    Matcher m = NMEA_PATTERN.matcher(gpsSentence);
    
    if (m.matches()) {
        String latitude = m.group(1);
        String longitude = m.group(2);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me crazy for a few days now. I have an
So my server has been going a bit crazy lately, every now and then
I've been with this exception all day and now I'm going crazy, I cannot
I've been going at this problem for a solid couple hours now and having
I've been driving myself crazy over the past few days over this one. We've
I've been going crazy with this: I have a banner which is structured like
I have been going crazy over this! I have an Air (2.6) app which,
I've been going stir crazy trying to install the ruby mysql gem here, and
Ok, I'm going crazy. I've been trying to make a simple .net assembly visible
I have been going crazy over a seemingly easy question with Python: I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.