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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:10:07+00:00 2026-06-15T23:10:07+00:00

So whenever the these two lines are commented out its fine, but with them

  • 0

So whenever the these two lines are commented out its fine, but with them it crashes.

EditText convertValue = (EditText) findViewById(R.id.et_value_convert);
TextView convertResult = (TextView) findViewById(R.id.txt_result);

here’s my full class code, xml is below.

package com.doubleelite.maxtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ConverterActivity extends Activity {

EditText convertValue = (EditText) findViewById(R.id.et_value_convert);
TextView convertResult = (TextView) findViewById(R.id.txt_result);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_converter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_converter, menu);
    return true;
}

// Custom method to handle button clicks.
public void onClick(View v) {
    switch(v.getId()) {

    case R.id.btn_to_cel:
        convertResult.setText(String.valueOf(convertFahrenheitToCelsius(Integer.valueOf(convertValue.getText().toString()))));
    }
}

private float convertFahrenheitToCelsius(float f) {
    return (f-32) * (5/9);
}

private float convertCelsiusToFahrenheit(float c) {
    return c * (9/5) + 32;
}

}

here is the xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ConverterActivity" >

<EditText
    android:id="@+id/et_value_convert"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="@string/text_value_convert"
    android:inputType="number"
    />

<Button
    android:id="@+id/btn_to_cel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_celsius"
    android:onClick="onClick"
    />

<Button
    android:id="@+id/btn_to_fahr"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_fahr"
    android:onClick="onClick"
    />

<TextView
    android:id="@+id/txt_result"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium"
    tools:ignore="HardcodedText" />

</LinearLayout>
  • 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-15T23:10:08+00:00Added an answer on June 15, 2026 at 11:10 pm

    Currently you are trying to find view’s before setting layout for Activity.change your code as :

    public class ConverterActivity extends Activity {
    
    EditText convertValue ;
    TextView convertResult;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_converter);
    
     convertValue = (EditText) findViewById(R.id.et_value_convert);
     convertResult = (TextView) findViewById(R.id.txt_result);
    }
    
     ///YOUR CODE HERE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my google app application, whenever a user purchases a number of contracts, these
I'm trying to use a MySQL database to save player information, but whenever there
I am working on the visual studio c++ and using these lines in my
I am trying to open these two files and read their contents into two
I want to know SHOULD I use these lines of code to include standard
Why isn't this code working? The app loads fine, however whenever I press the
I have some .xml files that are encoded in UTF-8 . But whenever I
In my code under GCC I get quite many warnings of these two types.
whenever we need to exception handling, we will surround with try/catch block, but when
I have configured a SMTP appender to send an email whenever there's an error.

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.