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 7625679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:13:24+00:00 2026-05-31T05:13:24+00:00

Hi I am starting my first android app and trying to get the TextView

  • 0

Hi I am starting my first android app and trying to get the TextView changed the words after some time.

public class Game1Activity extends Activity {

    GameViews ngv;
    private static String gameId = "game1Activity-game";
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game1_layout);
        ngv = (GameViews)findViewById(R.id.Game1);
        ngv.setTextView((TextView)findViewById(R.id.Text));
    };

}
public class GameViews extends View
{
    private TextView gameText;
    private long time1 = System.currentTimeMillis();

    public GameViews(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        initGameViews();
    }

    public GameViews(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        initGameViews();
    }

    public void setTextView(TextView tv)
    {
        gameText = tv;
    }

    public void initGameViews()
    {
        setFocusable(true);
        Resources r = this.getContext().getResources();
        changeGameText();
    }

    public void changeGameText()
    {
        while (true)
        {
            if (System.currentTimeMillis() - time1 > 100)
            {
                gameText.setText(R.string.hi2);
                return;
            }
        }
    }
}

the layout XML file is:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <game1.code.GameViews
    android:id="@+id/Game1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    tileSize="24" />

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:gravity="center" >

        <TextView
        android:id="@+id/Text"
        android:text="@string/hi1"
        android:visibility="visible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center_horizontal"
        android:textColor="#ff8888ff"
        android:textSize="24sp"/>
    </RelativeLayout>
</FrameLayout>

and the strings.xml is:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hi1">hi1</string>
    <string name="hi2">hi2</string>
</resources>

When I try to run, the logCat tells me that:

03-08 03:19:28.067: E/AndroidRuntime(602): Caused by: java.lang.NullPointerException
03-08 03:19:28.067: E/AndroidRuntime(602): game1.code.GameViews.changeGameText(GameViews.java:67)
03-08 03:19:28.067: E/AndroidRuntime(602):
game1.code.GameViews.initGameViews(GameViews.java:52)

It seems that the setText is causing the issue, as when I commented out this line there is no problem occurring.

Did I miss anything?

  • 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-05-31T05:13:25+00:00Added an answer on May 31, 2026 at 5:13 am

    You are setting the string value to some value in R.java not the value referenced by that R.java variable

    Change

    gameText.setText(R.string.hi2);
    

    to

    gameText.setText(getContext().getResources().getString(R.string.hi2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting Android app development and just after my very first app more complex
I'm starting my first Android app and after reading up I understand that the
I''m trying android SDK for the first time. I'm starting with the HelloAndroid tutorial.
This is my first Android app and I've encountered an exception when trying to
I'm trying to make an app for android using facebook's SSO, so first i
I am starting to build my first Android app. I have reached the point
I am new to Blackberry programming and starting my first app soon. I believe
Starting with no cache on server or client FIRST REQUEST GET /post/1 HTTP/1.1 HTTP/1.1
I'm starting on work on my first Windows Mobile 6.5 app in C#, and
This is my first android app and I'm a little disapponted because I'm not

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.