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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:07:40+00:00 2026-06-16T14:07:40+00:00

Here are my files (Conversion.xml, Conversion.java and AndroidManifest.xml). It is a small part of

  • 0

Here are my files (Conversion.xml, Conversion.java and AndroidManifest.xml). It is a small part of a project. I am able to get to the screen where I want to convert the power in watts to decibels. But when I enter the power value and click the button “Convert”, the app crashes and goes back to the my app home screen.

conversion.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ConvertTodB" >

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Enter the power in Watts"
        android:inputType="number"
        android:text="@string/et1" />

    <Button
        android:id="@+id/bConvert"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/Convert" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Result in dB"
        android:text="@string/et2" 
        android:textSize="20sp"/>

</LinearLayout>

Conversion.java

package com.example.rfconcepts;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.Math;

public class Conversion extends Activity {

    EditText entered_val;
    TextView result_val;
    Button bCon;

    @Override
    protected void onCreate(Bundle convertTodB) {

        super.onCreate(convertTodB);
        setContentView(R.layout.conversion);

        entered_val = (EditText) findViewById(R.string.et1);
        bCon = (Button) findViewById(R.id.bConvert);
        result_val = (TextView) findViewById(R.string.et2);

        bCon.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                if(entered_val.getText() != null && entered_val.getText().length() != 0){
                    result_val.setText(String.valueOf(10 * Math.log10(Double
                            .valueOf(entered_val.getText().toString()))));
                }

            }
        });
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.rfconcepts"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.rfconcepts.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.example.rfconcepts.Conversion"
            android:label="@string/app_name">
        </activity>
    </application>

</manifest>

I thank you in advance for the advise.

P.S:

Here is a list of things I did after reading a lot of solutions for various questions posted here.

  • Instead of using onClickListener, in conversion.xml, i added the attribute “android:onClick = “onClickConvert” and added the follwoing onClickConvert method in the Activity class.

public void onClickConvert(View v){
        if(entered_val.getText() != null && entered_val.getText().length() != 0){
            result_val.setText(String.valueOf(10 * Math.log10(Double
                    .valueOf(entered_val.getText().toString()))));
        }
    }

  • Changed Double.parseDouble() to Double.valueOf() (Although, I do not think this is the issue)

  • Checked if the editText itself has null, hence the if statement.

  • 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-16T14:07:41+00:00Added an answer on June 16, 2026 at 2:07 pm
    entered_val = (EditText) findViewById(R.string.et1);
    

    Why are you referring to a string? It should be an ID.

    You did not declare an ID for your EditTexts. Do something like this:

    <EditText
            [...]
            android:id="@+id/MyEditText"
             />
    

    Then you can refer to it like this:

    entered_val = (EditText) findViewById(R.Id.MyEditText);
    

    Also do the same with your TextView.

    Second issue:
    EditText.getText() returns an Editable, but you need a String. Convert it like this:

     if(entered_val.getText().toString() != null && entered_val.getText().toString().length() != 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert one xml file into another xml file using xslt.here, i
I downloaded the .php files from here , and I am able to take
I've included fancybox2 files like instructed here http://fancyapps.com/fancybox/#instructions using my extensions xml and <action
here's the trick. gotta convert 'bout 300 files from xls to csv, wrote some
I want to convert my sql data to csv files while clicking on a
I want to convert pdfs to image files within appengine. Ideally I would upload
I use these two files here and here . I created a class in
I am trying to patch dmenu with the files provided here: http://aur.archlinux.org/packages.php?ID=27334 I do
I am using T-SQL I have a few excel files located here: C:\MyFiles\ I
I'm trying to import the US Census cartographic boundary files (available here: http://www.census.gov/geo/www/cob/bdy_files.html )

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.