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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:21:02+00:00 2026-05-16T12:21:02+00:00

I am taking my first steps in Android and am starting with a very

  • 0

I am taking my first steps in Android and am starting with a very simple app which keeps track of progress through a knitting pattern and shows the instructions for the relevant row.

I want to update a couple of TextView objects programmatically. However, using getViewById() does not seem to identify them properly and the app crashes.

Having searched on Google it seems there are sometimes problems with the XML namespace in the layout XML but mine looks OK. Is it something to do with scope, perhaps?

instructions.java (this is the only activity)

package uk.co.oketchup.blanketsquare;

import android.app.Activity;
import android.os.Bundle;
import android.content.SharedPreferences;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.view.View;

public class instructions extends Activity
{
    private int mRow;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        /* retrieve row from shared preferences, or start from zero if nothing there */
        SharedPreferences settings = getPreferences(MODE_PRIVATE);
        mRow = settings.getInt("row",0);

        setContentView(R.layout.main);

        /* associate onClick listeners with the two buttons */
        final Button btnIncrement = (Button) findViewById(R.id.increment);
        btnIncrement.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Increment row
                ++mRow;
                calcAndUpdate();
            }
        });

        final Button btnDecrement = (Button) findViewById(R.id.decrement);
        btnDecrement.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Decrement row
                --mRow;
                calcAndUpdate();
            }
        });
    }

  private void calcAndUpdate() {
    String Instructions;
    int knit1;
    int knit2;
    int remaining;

    if (mRow%2 == 1 )
      {
        /* Odd row */
        knit1 = 40 - mRow;
        Instructions = "K" + knit1;
        remaining = knit1;
      }
      else
      {
        /* Even row */
        knit1 = 18 - mRow/2;
        knit2 = knit1 + 1;
        Instructions = "Sl 1, k" + knit1 + ", [sl 1 kwise] 2 times, k1, p2sso, k" + knit2;
        remaining = knit1 + knit2 + 2;
      }

    /* Update the display */
    TextView tRow = (TextView) findViewById(R.id.row);
    TextView tInstr = (TextView) findViewById(R.id.instr);
    TextView tStRem = (TextView) findViewById(R.id.stitchremain);

    /* Set the text */
    tRow.setText(mRow);
    tInstr.setText(Instructions);
    tStRem.setText(remaining);

  }

}

/res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  <TextView  
      android:id="@+id/row"
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Row"
      />
  <TextView  
      android:id="@+id/instr" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Instructions"
      android:layout_below="@id/row"
      />
  <Button
      android:id="@+id/increment"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="+"
      android:layout_alignParentBottom="true" />
  <Button
      android:id="@+id/decrement"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="-"
      android:layout_toRightOf="@id/increment"
      android:layout_alignParentBottom="true" />
  <TextView  
      android:id="@+id/stitchremain" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="stitches remaining"
      android:layout_above="@id/increment"
      />
</RelativeLayout>

The TextView objects seem to have been registered ok as they appear in R.java

public static final class id {
    public static final int decrement=0x7f050003;
    public static final int increment=0x7f050002;
    public static final int instr=0x7f050001;
    public static final int row=0x7f050000;
    public static final int stitchremain=0x7f050004;
}

Here is the error message shown in ddms.

Uncaught handler: thread main exiting due to uncaught exception
android.content.res.Resources$NotFoundException: String resource ID #0x1
    at android.content.res.Resources.getText(Resources.java:200)
    at android.widget.TextView.setText(TextView.java:2813)
    at uk.co.oketchup.blanketsquare.instructions.calcAndUpdate(instructions.java:75)
    at uk.co.oketchup.blanketsquare.instructions.access$100(instructions.java:11)
    at uk.co.oketchup.blanketsquare.instructions$1.onClick(instructions.java:33)
[etc]

Many thanks for your help.

  • 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-16T12:21:02+00:00Added an answer on May 16, 2026 at 12:21 pm

    mRow is an integer. When you call setText(mRow) on line 75, it thinks that you are trying to set the text with a String resource with ID = the value of mRow.

    Instead, do:

    tRow.setText(Integer.toString(mRow));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am taking my first steps programming in Lua and get this error when
I am taking my first foray into PHP programming and need to configure the
I've been taking a look at some different products for .NET which propose to
Taking over some code from my predecessor and I found a query that uses
Taking shs's question a step further... Why isn't all government sponsored software open source?
Taking advice from this post , I purchased a copy of 'The C Programming
Taking CPU affinity into account, will such an environment be useful with threading? Or
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
I'm taking the leap: my PHP scripts will ALL fail gracefully! At least, that's
What's the best (taking both speed and readability into account) way to determine if

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.