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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:07:30+00:00 2026-06-04T04:07:30+00:00

I am trying to display the float value degrees as a string in a

  • 0

I am trying to display the float value “degrees” as a string in a TextView on my layout, but receive a NullPointerException on tv.setText(mydegrees); I have tried numerous methods to convert the float to a usable string value, but can’t seem to get the TextView to display the float value. Any help would be greatly appreciated!

Note: The degrees is manipulated by an onTouchEvent

TextView from XML:

<TextView
android:id="@+id/current_degrees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center"
android:text="@string/app_name"
android:textColor="#FFFF00" />

Java Code:

float degrees = (float) -65;
String mydegrees = String.format("%.2f", degrees) ;

//...

public void pushClick(View pushClick) {
    switch (pushClick.getId()) {
    case R.id.btn_push:

        TextView tv = (TextView) findViewById(R.id.current_degrees);
        tv.setText(mydegrees);
  • 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-04T04:07:32+00:00Added an answer on June 4, 2026 at 4:07 am

    Edit: As @Jake King noted, in my previous answer I was not paying attention to the details (that your mydegree member is a String instance.

    This way the only reason for you to get a NPE is that your tv TextView is null.

    Please check your layout xml file you use for the activity / renderer / view, and make sure you have there a TextView or any extension of it with @+id/current_degrees.

    Also, your title is very misleading: If you have your float declared and initialized as above, then there cannot be any NullPointerException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I convert a string to a float in Objective-C? I am trying
I'm sure this will be ridiculously simple, but whatever... I'm trying to display a
I am trying to display a form in IE, but for some reason, the
I am having a really odd problem trying to set a simple float value
I have a form layout that I want to display the label aligned left
I have an image with detected circles and am trying to read value of
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying to display some files in a web page so the user can
Ive been trying to display formatted content blocks from a xml file with no
I am trying to display the contents of a .cpp file in php. I

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.