Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to return a string from java project into android project

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to return a string from java project into android project

    I tried many times to return a string from java project to an android project But it keeps sending incorrect values as in 2 as it should be 1 here is an example.

    Java Project:

    boolean somethingboolean = false;  
    if(something.equals("1")){  
    somethingboolean = true;  
    }  
     
    public static String getString(){  
    if(somethingboolean == true){  
    return "TRUE";  
    }else{  
    return "FALSE";  
    }  
    }

    Android project:
    System.out.println(JavaProject.getString())


    and in the android project it prints "FALSE"

    So what should i do? Thanks for all...


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: How to return a string from java project into android project

    This thread has been cross posted here:

    http://www.java-forums.org/android/90175-how-return-string-java-project-into-android-project.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,065
    My Mood
    Mellow
    Thanks
    184
    Thanked 652 Times in 639 Posts

    Default Re: How to return a string from java project into android project

    "FALSE" is certainly a legitimate result of the code you've posted. If you believe it's wrong, please explain why and post enough code to justify your description.

    This statement:

    if(somethingboolean == true)

    can be reduced to:

    if( somethingboolean )

    but that won't change your outcome.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,659
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: How to return a string from java project into android project

    If you are dealing with statics, you probably have some sort of data modification going on which is leading to unexpected results. It's hard to say exactly what the problem is with the example you provided.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Forum VIP
    Join Date
    Jun 2011
    Posts
    313
    My Mood
    Bored
    Thanks
    46
    Thanked 87 Times in 73 Posts
    Blog Entries
    4

    Default Re: How to return a string from java project into android project

    You should use android.util.Log for printing to the android logcat. I have heard of some android builds that will automatically pipe System.out to the logcat but typically an android device won't have a console so System.out.println behaves unpredictably.

    I'd suggest you put a breakpoint in the getString method and step through the code. I'm betting that somethingboolean isn't being set but your code fragment isn't telling the full story.

Similar Threads

  1. Replies: 1
    Last Post: April 6th, 2014, 05:16 PM
  2. Java School Project Help; Project #2, In Danger of Failing.....
    By john++ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2014, 02:35 AM
  3. Help with java project?
    By Manny01 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 3rd, 2013, 11:21 AM
  4. College project: XML file from PC to Android
    By StudioGilliam in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 1st, 2012, 04:42 AM
  5. [SOLVED] Return randomized String to other class in project
    By Fermen in forum Collections and Generics
    Replies: 2
    Last Post: February 16th, 2011, 04:36 PM

Tags for this Thread