Java/android noob, passing variables to function
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Java/android noob, passing variables to function

  1. #1
    Join Date
    Nov 2010
    Posts
    1

    Java/android noob, passing variables to function

    Okay so I'm VERY new to java and I'm trying to make a very simple android program. Basically I have a function, it will take in two integers and then display their product. But I don't think I'm passing the variables to the function correctly. Also I'm probably not converting the numbers to strings the right way (there doesn't appear to be a string datatype in standard java so i need some sort of library or something i assume).

    Anyways here's the code

    Code:
    package com.muc.whatever;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class helloagain extends Activity 
    {
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            FUNCTION_1(3,4);
        }
        public void FUNCTION_1(int A,int B)
        {
            setContentView(R.layout.main);
            TextView tv = new TextView(this);
            tv.setText(A*B);
            setContentView(tv);
        }
    }

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java/android noob, passing variables to function

    But I don't think I'm passing the variables to the function correctly.
    What makes you think that? Does it not compile, does it not work? Unless you tell us what is wrong we can't help you fix it.
    there doesn't appear to be a string datatype in standard java
    There is a String class for handling strings. If you want to convert numbers to a String there are a few ways of doing it. One way is to use the String class which has a set of overloaded valueOf(..) methods which you can use to convert primitives to a string representation of the value.

    Read the API docs for java.lang.String.

    And whilst you are reading stuff, read up on Java naming conventions or people are going to struggle to read your code.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center