Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Development for Beginners : Practice Set 2 Email Directory Example
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);
@fadygh

This comment has been minimized.

Copy link

commented Aug 11, 2016

I changed the display method from int to String and it works
public void display (String i) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText(""+i);

@Dorha85

This comment has been minimized.

Copy link

commented Jan 15, 2017

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
    display (contactInfo);
@swapanpal

This comment has been minimized.

Copy link

commented Jan 30, 2017

String firstName = "Lyla";
String lastName= "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + "<" + firstName.toLowerCase() + "." + lastName.toLowerCase() + "@justjava.com>";
display("" + contactInfo);

@madmat27

This comment has been minimized.

Copy link

commented Jan 31, 2017

As suggested:

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
    display(contactInfo);
}
@Manoj0718

This comment has been minimized.

Copy link

commented Feb 8, 2017

screenshot 2017-02-08 19 17 12
how can I get rid of this? it says
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.manoj.practiceset02, PID: 13833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.manoj.practiceset02/com.example.manoj.practiceset02.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

@wertimo

This comment has been minimized.

Copy link

commented Feb 14, 2017

@fadygh thanks mate it worked

@krishsam02

This comment has been minimized.

Copy link

commented Mar 10, 2017

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo+ = "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

output would be: Lyla Fujiwara/<Fujiwara.Lyla@justjava.com/>

@kostromina

This comment has been minimized.

Copy link

commented Mar 22, 2017

2 last lines of code are not actually correct (in case we want to display name and email)

@nnannos

This comment has been minimized.

Copy link

commented Apr 9, 2017

It is error. It shows:
Fujiwara.Lyla@justjava.com

@Dano79

This comment has been minimized.

Copy link

commented Apr 16, 2017

So where do we paste this code in java main after on create ?

@LuckyRathod

This comment has been minimized.

Copy link

commented Jun 21, 2017

image

I have used toLowerCase() method

@JobVillagran

This comment has been minimized.

Copy link

commented Jun 27, 2017

I'm getting this error, some help please.

captura

@ismailsahinpersonal

This comment has been minimized.

Copy link

commented Jul 1, 2017

Hi JobVillagram, reason of getting error is your display method. Because you want an integer value but you are passing String value to method. You must to change variable type of your display method with String.

@Mahmoudtarek59

This comment has been minimized.

Copy link

commented Aug 17, 2017

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo =contactInfo+ "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@Aelos7

This comment has been minimized.

Copy link

commented Oct 4, 2017

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(lastName + " " + firstName + contactInfo);

I put it in the display ...works jut as well

@marablomst

This comment has been minimized.

Copy link

commented Dec 9, 2017

great, i submitted good answer and it was rejected. there is something wrong with this one @udacity

@beniza

This comment has been minimized.

Copy link

commented Dec 10, 2017

@marablomst, you are right. I tried several times with the good answer (I've even copied and pasted the answer suggested by the bot), but it was rejected. @udacityandroid please look into this one. Here's my code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    contactInfo += "<" + lastName.toLowerCase() + "." + firstName.toLowerCase() + "@justjava.com" + ">";
    display(contactInfo);
}
@Nyasser

This comment has been minimized.

Copy link

commented Dec 28, 2017

hello guys,
how do we display many results in the screen ? like
display1(...
display2(...
Do we need to create a method for each or there is an easier way?
Thank you

@DeusXmac

This comment has been minimized.

Copy link

commented Jan 6, 2018

should be like this;
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = ""+ firstName +" "+ lastName +" <" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@R964

This comment has been minimized.

Copy link

commented Jan 21, 2018

I can not find the mistake... Please, I will need help
screenshot 2018-01-21 19 07 11

@Trubius

This comment has been minimized.

Copy link

commented Jan 24, 2018

@R964 use this gist for display:
public void display(String text) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText(text);
}

@maiossaid

This comment has been minimized.

Copy link

commented Jan 29, 2018

@Maxwe1

This comment has been minimized.

Copy link

commented Jan 31, 2018

Not correct.
it's displaying:
Fujiwara.Lyla@justjava.com

@Nogaeman

This comment has been minimized.

Copy link

commented Feb 3, 2018

The Result of code
1
So This Not Correct

The Correct Code To Achieve The Goal Is

  String firstName = "Lyla";
        String lastName = "Fujiwara";
        String contactInfo = firstName + " " + lastName;
        contactInfo = firstName + " " + lastName + "<" + lastName + "." + firstName + "@justjava.com>";
        display(contactInfo);

untitled

@Noupha

This comment has been minimized.

Copy link

commented Feb 9, 2018

the code should be:
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + ”<“ + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

What is displayed would be:
Lyla FujiwaraFujiwara.Lyla@justjava.com

@abdahma01

This comment has been minimized.

Copy link

commented Feb 13, 2018

untitled

@MahmoudMabrok

This comment has been minimized.

Copy link

commented Feb 16, 2018

@Manoj0718 could you screen the code

@peteribrahimgorgy

This comment has been minimized.

Copy link

commented Feb 18, 2018

only setting part of the needed out put

image

@first-hero

This comment has been minimized.

Copy link

commented Feb 24, 2018

not correct
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);............................................<Fujiwara.Lyla@justjava.com>
screenshot_20180224-095234 1

to display the correct message the code will be

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);
screenshot_20180224-101058 1

@Chevoo

This comment has been minimized.

Copy link

commented Mar 2, 2018

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo= firstName+" "+lastName;
contactInfo+="<" + lastName+"."+firstName+"@justjava.com>";
display(contactInfo);

@ak3096

This comment has been minimized.

Copy link

commented Mar 4, 2018

String firstName ="Lyla";
String lastName ="Fujiwara";
String contactInfo=firstName+" "+lastName;
contactInfo= contactInfo+"<"+lastName+"."+firstName+"@justjava.com>";
display(contactInfo);

@wardiemotivations

This comment has been minimized.

Copy link

commented Mar 6, 2018

hey everyone, I am getting the same errors as @R964 and @JobVilligran please help @udacityandroid

@louayeldin

This comment has been minimized.

Copy link

commented Mar 16, 2018

image

@conbradst

This comment has been minimized.

Copy link

commented Apr 6, 2018

Given

String firstName = "Lyla";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";

    display(contactInfo);

Corrected Code

String firstName = "Lyla ";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = " <" + lastName + "." + firstName + "@justjava.com>";

    display(firstName + lastName + contactInfo);
@conbradst

This comment has been minimized.

Copy link

commented Apr 6, 2018

Another option to correct program...

String firstName = "Lyla ";

    String lastName = "Fujiwara";

    String contactInfo = firstName + " " + lastName;

    contactInfo = firstName + lastName + " <" + lastName + "." + firstName + "@justjava.com>";

    display(contactInfo);
@Imsurajkr

This comment has been minimized.

Copy link

commented Apr 15, 2018

Hey i got the
Error :- Stirng cannot be converted to int and i solved this issue so what we have to do is change the value of public void to string value

String firstName = "Lyla"; String lastName = "Fujiwara"; String contactInfo = firstName + " " + lastName; contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>"; display1(contactInfo);
// This is the right java code and the programme will run fine .
public void display1(String text) { TextView t = (TextView) findViewById(R.id.display_text_view); t.setText(text); }

Happy to Help

@OluwatobilobaLight

This comment has been minimized.

Copy link

commented May 16, 2018

`package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    contactInfo = contactInfo + " <" + lastName + "." + firstName + "@justjava.com>";
    display(contactInfo);
}
/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */

public void display(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text);
}

public void display(int text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text + "");
}

public void display1(String text) {
    display(text);
}

public void display2(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_2);
    t.setText(text);
}

public void display3(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_3);
    t.setText(text);
}

}`

screenshot_1526481105

@megaunknown

This comment has been minimized.

Copy link

commented May 17, 2018

The fix is

String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo +="<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@Mohanad0

This comment has been minimized.

Copy link

commented May 26, 2018

111

@tooptooptoop

This comment has been minimized.

Copy link

commented Jun 2, 2018

screenshot_2018-06-02-14-21-36 1
package com.example.android.practiceset2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String conttactInfo = firstName + " " + lastName;
    conttactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
    display(conttactInfo);

}

/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */
public void display(String i) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(""+ i);
}

}

<TextView
    android:id="@+id/display_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="45sp" />
@ZahraaElhaj

This comment has been minimized.

Copy link

commented Jun 2, 2018

it's displaying:
Fujiwara.Lyla@justjava.com

@ahmedmtaher

This comment has been minimized.

Copy link

commented Jun 7, 2018

@gemjack

This comment has been minimized.

Copy link

commented Jun 12, 2018

package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // PASTE CODE YOU WANT TO TEST HERE

    String firstName = "Lyla";
    String lastName = "Fujiwara";
    String contactInfo = firstName + " " + lastName;
    String contactName = firstName + " " + lastName;
    contactName = (firstName + " " lastName);
    contactInfo = "<" + firstName + "." + lastName + "@justjava.com>";
    display(contactName);
    display2(contactInfo);


}

/**
 * Display methods that allow the text to appear on the screen. Don't worry if you don't know
 * how these work yet. We'll be covering them in lesson 3.
 */

public void display(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view);
    t.setText(text);
}

// public void display(int text) {
// TextView t = (TextView) findViewById(R.id.display_text_view);
// t.setText(text + "");
// }

public void display1(String text) {
    display(text);
}

public void display2(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_2);
    t.setText(text);
}

public void display3(String text) {
    TextView t = (TextView) findViewById(R.id.display_text_view_3);
    t.setText(text);
}

}

image

@gemjack

This comment has been minimized.

Copy link

commented Jun 12, 2018

This worked for me...

@raDIUM2010

This comment has been minimized.

Copy link

commented Jun 12, 2018

@Torh-21

This comment has been minimized.

Copy link

commented Jun 14, 2018

Correct Code:

screenshot_2018-06-14-05-15-54
String firstName = "Lyla";
String lastName = "Fujiwara";
String contactInfo = firstName + " " + lastName;
contactInfo = contactInfo + "<" + lastName + "." + firstName + "@justjava.com>";
display(contactInfo);

@jerylee

This comment has been minimized.

Copy link

commented Jun 26, 2018

image

@waelfareed

This comment has been minimized.

Copy link

commented Nov 17, 2018

@shankar-shiv

This comment has been minimized.

Copy link

commented Dec 23, 2018

Done!

package com.example.android.practiceset2;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // PASTE CODE YOU WANT TO TEST HERE

        //  int weekday = 5;
        //  int weekend = 9;
        //  int optimalHours = 7 * 8;

        //  int actualHours = weekday;
        //  actualHours = actualHours + weekend * 2;
        //  int solution = optimalHours - actualHours;
        //  display(solution);

        // int dollars = 40;
        // int dollarsToYen = 119;
        // int yen = dollarsToYen * dollars;
        // display(yen);

        String firstName = "Shiva";
        String lastName = "Shankar";
        String contactInfo = firstName + " " + lastName;
        contactInfo = "<" + lastName + "." + firstName + "@justjava.com>";
        display(contactInfo);

    }

    /**
     * Display methods that allow the text to appear on the screen. Don't worry if you don't know
     * how these work yet. We'll be covering them in lesson 3.
     */

    public void display(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view);
        t.setText(text);
    }

    public void display(int text) {
        TextView t = (TextView) findViewById(R.id.display_text_view);
        t.setText(text + "");
    }

    public void display1(String text) {
        display(text);
    }

    public void display2(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view_2);
        t.setText(text);
    }

    public void display3(String text) {
        TextView t = (TextView) findViewById(R.id.display_text_view_3);
        t.setText(text);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.