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

  • SEARCH
  • Home
  • 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 8620761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:39:26+00:00 2026-06-12T06:39:26+00:00

team1name is initialized in the begining of the widget class String team1name= null; But

  • 0

team1name is initialized in the begining of the widget class

String team1name= null;

But when I return a string from the getAcronym() and assign to team1name, I get a null pointer exception. How do I resolve this
Here’s the code

public void onReceive(Context context, Intent intent){
    Bundle extras = intent.getExtras();
    if (extras == null) {
        return;
    }

    team1name = extras.getString("team1name");
    team2name = extras.getString("team2name");
    team1score = extras.getString("team1score");

    team2score=extras.getString("team2score");

    player1=extras.getString("player1");
    player2=extras.getString("player2");
    extras=null;

    team1name=getAcronym(team1name);        // Null Pointer Exception
    team2name=getAcronym(team2name);

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

    remoteViews.setTextViewText(R.id.team1name, team1name);
    remoteViews.setTextViewText(R.id.team2name, 
    ComponentName cn = new ComponentName(context, MyWidgetProvider.class);  

    AppWidgetManager.getInstance(context).updateAppWidget(cn, remoteViews);
}


String getAcronym(String teamName){
    if(teamName.equals("Australia")){
        teamName="AUS";
    }else if(teamName.equals("Pakistan")){
        teamName="PAK";
    }else if(teamName.equals("India")){
        teamName="IND";
    }else if(teamName.equals("England")){
        teamName="ENG";
    }else if(teamName.equals("Sri Lanka")){
        teamName="SL";
    }else if(teamName.equals("South Africa")){
        teamName="RSA";
    }
    return teamName;
}
  • 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-12T06:39:27+00:00Added an answer on June 12, 2026 at 6:39 am

    Your getAcronym(String teamName) method does not do any null checking. Add the line:

    if(teamName==null){
        return "";
    } 
    

    before you start checking for the string value, and this should alleviate your problems.

    Might be work checking to see why teamName is being passed through as null, if it is intentional then this solution will work fine. If you should always be sending a valid teamName through, then there is somewhere in your code before you get to your widget where it is not being assigned properly.

    Also, if your strings are not constant, i.e they could conceivably be “England” or “england”, you should do a comparison where the case is ignored to catch these instances.

    i.e

     if(teamName.equalsIgnoreCase("Australia")){
        teamName="AUS";
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So in my web service i get the data from textboxes search it in
this is my models.py from django.db import models # Create your models here. class
I produce an int from JSON data var f_page = [TheHouseofMarley]; retrieveData(f_page[0]); function retrieveData(teamName)
I have String s that are put into an ArrayList randomly. private ArrayList<String> teamsName
I made a linq query which i want to pass to the view but
I have a jquery function gets a all teams from a service. How would
I have gone mad trying to bind the json string to the dropdown. Please
Hello I am trying to display the constraints in one of my tables but
This is quite hard to explain. I have a class which should support the
Hey how can I combine the two queries below into one?? so I get

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.