-
-
Save udacityandroid/332432b53a13e5c55c1c to your computer and use it in GitHub Desktop.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="com.example.android.practiceset2.MainActivity"> | |
<TextView | |
android:id="@+id/display_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
</LinearLayout> |
All works for me, thanks a lot.
works fine.
If anyone is getting an error in your tools:context="com.example.tom.practiceset2.MainActivity
where part or all of the text is showing up in red, please try this:
- In your Project Explorer (left "explorer-like" pane of Android Studio), navigate to:
app > manifests > AndroidManifest.xml
and double click that file to edit it:
- On line 3, copy the value of the package attribute:
package="com.example.tom.practiceset2"
- On line 7 in your
activity_main.xml
, paste that value into:tools:context="PASTE VALUE HERE"
- On line 1 in your
MainActivity.java
, paste that value again into:package PASTE VALUE HERE
- On the menu, click BUILD > CLEAN PROJECT
- On the menu, click BUILD > REBUILD PROJECT
- Run the app
The reason for this error is because the company domain was left at its default value, which was likely different than the values in these gists. All we did in these steps was to make sure all the values for the company domain are in sync. The screen for this practice exercise should look like this:
Hope this makes sense and it helps!
Done
@tomnta thank you1
tools:context="com.example.android.practiceset2.MainActivity">
The error message i'm getting is "Typo in word "practiceset"
What do i do please
for some weird reason the android studio misspelt the android.example.com as "andriod" recreate you project and correct it then it will work. I am using a Mac. I hope this helps someone.
it works well
it works fine!!!
for those having problems with package name, on the updated android studio the word android is left out of package name. try deleting android from package name
Worked for me.
I close and open other projects. When I openned again ".MainActivity" wasn't red in "activity_main.xml" nor "AndroidManifest.xml". Although some other terms were in red in the MainActivity.java
Substituted:
import android.support.v7.app.AppCompatActivity;
for
import androidx.appcompat.app.AppCompatActivity;
and it runned in the phone.
Before the only thing that was in red was ".MainActivity", there were no errors when I run, but the app crashed on the phone.
Do you gyus have the project name as Practice Set 2, or Practise Set 2?
The thing is it should be practice with two "C"s, not with a "c" and then "s".
this must be it! Thanks...
Hi guys,
I know it can be hard sometimes but look at that way. Once you understand how to fix these kind of errors, you will be faster next time. I mean, certainly by the time there are new features/updates and if you learn the technique, you will fix any future errors more likely.
My errors came after copy paste and certainly even my created project package name wasn't the same, so... Look at my package name and what I changed in XML and Java file. Good luck.
It is leaving some kind of errors.
it's 16/01/2020 and this the code that's work for me i have android version 3.5.3 for Windows 64-bit
`package com.example.practiceset2;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import com.example.practiceset2.R;
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
}
/**
* 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);
}
}`
if it doesn't work for you then try to change the package name in first line (First line of above code) with your actual package name which you can also find in first line of your android studio's MainActivity.java class
i need a help to understand " why the 1st text don't show and the name of the app doesn't show also"
This is my java code :
package com.example.practiceset2;
import android.os.Bundle;
import androidx.appcompat.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);
display1("This is Box 1.");
display2("And this is Box 2.");
display3("And look! Box 3!");
}
/**
* 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);
}
}
i need a help to understand " why the 1st text don't show and the name of the app doesn't show also"
This is my java code :
Hi @AMAbdElhameed,
Your java file is ok, I tested and shows all the TextViews.
I tested the XML file what Udacity shared here, that's also ok.
Your problem is in the file name.
In java file your code is that:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display1("This is Box 1.");
display2("And this is Box 2.");
display3("And look! Box 3!");
}
So, it uses "activity_main" XML file. Your XML file name is: "content_main.xml"
All you need to do is:
- to rename your XML file to "activity_main"
or - to rename your "activity_main" input in java file to "content_main".
Try using this one it worked for me
package com.example.practiceset2;
import android.os.Bundle;
//import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
//import java.text.NumberFormat;
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
}
/**
* 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);
}
}
Guys don't worry, just try a solution.
In activity_main.xml file
Replace this: tools:context="com.example.android.practiceset2.MainActivity">
To this: tools:context="com.example.practiceset2.MainActivity">
and in MainActivity.java file
Replace this: package com.example.android.practiceset2;
To this: package com.example.practiceset2;
one suggestion from my side :- DO NOT COPY-PASTE THE CODE AS TOLD BY THE INSTRUCTOR.
rather build up the code as given here in the gist.
actually i had issue of app crashes and what not.
i made a new project and rebuilt the code on my own and it worked
In activity_main.xml file
Replace this: tools:context="com.example.android.practiceset2.MainActivity">
To this: tools:context="com.example.practiceset2.MainActivity">
and in MainActivity.java file
This is the Final Working code for me.
I'm using Windows 10 (64 bit), and android studio 4.2 (beta 4).
_I tried the solution by @fedor90 and then the following code:_
### **for "activity_main.xml":**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.practiseset2.MainActivity">">
<TextView
android:id="@+id/display_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
<TextView
android:id="@+id/display_text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
<TextView
android:id="@+id/display_text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
</LinearLayout>
**### for "MainActivity.java "**
package com.example.practiseset2;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import com.example.practiseset2.R;
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
}
/**
* 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);
}
}
``
for those who are facing a issue with unable to resolve display_text_view issue just check your text view id because in my id "+" was not present
Thank you!
It works for me, thanks!