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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:11:32+00:00 2026-06-13T00:11:32+00:00

I’m pretty new to Java and Android. I’m trying to make an app that

  • 0

I’m pretty new to Java and Android. I’m trying to make an app that calculates a volume of a liquid in a cylinder, then return the result to a textView box. But now when I click the button to Calculate, it is crashing and I don’t know what I’m missing. Everything compiles fine.

package com.somename.fuel.volume.calculator;

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

public class CalculateCylinder extends Activity {

EditText length, width, height, depth;
TextView result;
Button calculate;
double firstNum, secNum, thirdNum, volume, area;
double liqVolume;
double radius;
double a, l, aSide,aTop,b,Arc,FluidSurfaceAreaTotal,r,d,v,h,fsal;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.calculate_cylinder);

    calculate = (Button) findViewById(R.id.buttonCylCalc);

    length = (EditText) findViewById(R.id.editCylLength);
    height = (EditText) findViewById(R.id.editCylHeight);
    depth = (EditText) findViewById(R.id.editCylDepth);
    result = (TextView) findViewById(R.id.buttonCylResult);

    calculate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            //Toast.makeText(getApplicationContext(), (CharSequence) result, Toast.LENGTH_LONG).show();
            try {
                calculate();
            } catch (Exception e) {
                e.printStackTrace();
            }
            result.setText((CharSequence) result);
        }

        public TextView calculate() throws Exception {
            // TODO Auto-generated method stub
            double firstNum = Double.valueOf(length.getText().toString());
            double secNum   = Double.valueOf(height.getText().toString());
            double thirdNum = Double.valueOf(depth.getText().toString());

            radius = (secNum/2);
            area = ((secNum*secNum)*3.14);
            //liqVolume = (firstNum) * (radius*radius)(acos(radius-depth/radius))
            // Cubic Volume

            v = aSide * l;
            // Fluid surface Area, Side
            aSide = (r*r)*(3.14 / 2 -Math.acos(1-h/r)) - (r-h)*Math.sqrt(h*(2*r-h));
            // Fluid Surface Area Top
            aTop = 2*Math.sqrt((r*r)-((r-h)*(r-h) * l));
            // Fluid Surface Area Bottom
            b = fsal*l;
            // Fluid Surface Area Total
            FluidSurfaceAreaTotal = 2*aSide+aTop+b;
            // Cylinder Radius
            r = d/2;
            // Cylinder Diameter
            d = 2*r;
            if (h <= r )
                // Fluid Side Arc Length
                fsal = 2*r*Math.acos((r-h)/r);

            else if (h > r)
                fsal = 2*r*(3.14-Math.acos((h-r)/r));
            return result;
            }


    });
}   

}

Here is a logcat:

10-18 05:24:38.893: E/AndroidRuntime(964): FATAL EXCEPTION: main
10-18 05:24:38.893: E/AndroidRuntime(964): java.lang.ClassCastException:    android.widget.Button
10-18 05:24:38.893: E/AndroidRuntime(964):  at   com.dbryant423.fuel.volume.calculator.CalculateCylinder$1.onClick(CalculateCylinder.java:55 )
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.view.View.performClick(View.java:2408)
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.view.View$PerformClick.run(View.java:8816)
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.os.Handler.handleCallback(Handler.java:587)
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.os.Looper.loop(Looper.java:123)
10-18 05:24:38.893: E/AndroidRuntime(964):  at android.app.ActivityThread.main(ActivityThread.java:4627)
10-18 05:24:38.893: E/AndroidRuntime(964):  at java.lang.reflect.Method.invokeNative(Native Method)
10-18 05:24:38.893: E/AndroidRuntime(964):  at java.lang.reflect.Method.invoke(Method.java:521)
10-18 05:24:38.893: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-18 05:24:38.893: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-18 05:24:38.893: E/AndroidRuntime(964):  at dalvik.system.NativeStart.main(Native Method)

I’ve been wracking my brains to try to figure out how to do the math on this, and I’ve not been able to find the answer to why it’s crashing. I’m sure it’s probably something simple that I’ve missed somewhere. If you need more information from the other files let me know, but this one seem the be the only one with the problem. I also know that there is unused variables that I’ve not removed yet.

  • 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-13T00:11:33+00:00Added an answer on June 13, 2026 at 12:11 am
    result.setText((CharSequence) result);
    

    This line cause Exception because you are casting Android View class to CharSequence Class.

    Possible Solution:

    Change return type of your method public TextView calculate() to

    public String calculate()
    

    Now in method public String calculate() return String of result fsal

    And your button’s Click() is something like,

    calculate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //Toast.makeText(getApplicationContext(), (CharSequence) result, Toast.LENGTH_LONG).show();
               String resultValue = "";
                try {
                 resultValue =  calculate();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                result.setText( resultValue);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.