Need Help - quick question about my app

Last Updated:

  1. Hi Everyone,

    I am relatively new to Android Development, though I have tinkered around quite a bit and taken a 3 day accelerated course on Android development.

    With that being said, I am working on a simple but specialized calculator app to get my feet [more] wet. I have 2 activities, MainActivity in which a user inputs information, and ResultsActivity, in which the app takes that info, and runs some calculations. About six months ago, I wrote a Calculator class in C++, I converted it to Java in hopes of using it here.

    I was able to integrate the Calculator class into my project and syntactically everything looks great. However, once I try creating a Calculator object in the ResultsActivity, my app no longer runs.

    My question is that am I missing something in the Manifest? I realize I need to specify all Activities in the Manifest, but do I need to somehow specify this Calculator class as well? How would I do that?

    Does anyone have any other ideas?


  2. AndreMu

    AndreMu New Member

    Hi Billiusmaximus,
    Have you checked the debugging window for an error message?
    You say that the application stops running, and by that I assume it crashes, so there is a good chance there's an exception being thrown, which should give you an idea of where your error is located.

    As far as I know, you do not have to specify your use of the Calculator class in the manifest, since its just a simple class. You can always test this by implementing a simple class, which is less prone to errors :)

    Hope this helps, if the error message doesn't make sense Im sure some of the pro's here can give a hand :)

    Cheers, Andr
  3. Hi,

    Thank you for responding. I figured out how to fix it... but I don't know why.

    I don't know Java very well since I did most of my schoolwork in C/C++, but I noticed that if I did not use my parameterized constructor and instead used a default constructor then followed up with a 'set' function to initialize the private data members, it works just fine.

    //Parameterized Constructor:
    public Calculator(a, b, c, d){

    //Default COnstructor:
    public Calculator(){}

    public Set(a, b, c, d){

    Is it possible that Java does not like parameterized constructors? I never had any syntax errors.

  4. AndreMu

    AndreMu New Member

    Hi Billy,
    It is difficult to tell what is going on in your code, so it is hard to help you out :)
    For instance, are the private variables declared before the constructor?
    What error do you get?

    But I can tell you that parameterized constructors work fine in Java :)

    Do you use Eclipse by the way? if not I can recommend it! (freely available at Eclipse Downloads , and the Android Dev. Tool install is well documented at ADT Plugin for Eclipse | Android Developers)

    Good luck with the calculator,
  5. Hi,

    Yes, I did declare my private data members before the constructor. And yes, I am using Eclipse with the ADT plugin, though I have not yet learned how to use the debugger.

    I can try looking into that and re-implementing the old constructor again...

    Thanks for the help, I will post anymore questions I have.

  6. Hi,

    This is not exactly related to my thread.

    However, I tried displaying floating point numbers in a TextView but it wasn't working. Is there some other way I am supposed to display floating point numbers?

  7. Boogs

    Boogs Well-Known Member

    Perhaps it has something to do with the way your parameters are passed in the stack to your constructor. Are you passing them as references or as their actual values to the C++ constructor or function?
  8. I figured out what my problem was. I was trying to use the data type 'float' which is not an acceptable parameter in the EditText setText function. I discovered that if I used Java's Float object, I can tack on the toString() method and it works just fine.

    Yep, not only attempting to learn the android system, but also the Java language itself.. @_@

    Still have yet to figure out how to set the precision of the floating point number displayed.


Share This Page