Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Development for Beginners : Starter Gist for Java
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
}
/**
* 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);
}
}
@manmeet-22

This comment has been minimized.

Copy link

commented Sep 21, 2016

In the first line the code sis not work for me-

package com.example.android.practiceset2;

I tried this instead-

package com.androidexample.practiceset2;

@aparnasridhar

This comment has been minimized.

Copy link

commented Sep 22, 2016

@manmeet-22 - the second instruction in the following video asks you to set company domain as android.example.com. You have set your company domain as androidexample.com and hence you needed to change the above gist. Good job identifying what to change to match your package !

https://classroom.udacity.com/nanodegrees/nd803/parts/8031345402/modules/783062863775460/lessons/4036438656/concepts/42760363080923#

@Sandy-O

This comment has been minimized.

Copy link

commented Oct 13, 2016

I just deleted the code starting at @override on my project then pasted the code from this page starting with Line 9 @override and down.
I had no errors except for display_text_view which I will fix as I continue to code my project.

@ajayanku

This comment has been minimized.

Copy link

commented Nov 3, 2016

![screenshot 44](https://cloud.githubusercontent.com/assets/23082835/19968922/94d1dc68-a1fc-11e6-9f8a-7f8ff128b7
i have copy and paste the code in main activity.java. Its not working pls tell me what am i do

@almeida1492

This comment has been minimized.

Copy link

commented Jan 6, 2017

it's not being able to extend to AppCompatActivity

@Basslo

This comment has been minimized.

Copy link

commented Jan 25, 2017

All the capital R turns red on my Android studio. What is your advice?

@learn2develop

This comment has been minimized.

Copy link

commented Jan 27, 2017

In your file delete everything starting with the line public class and copy in the everything from the code above starting from the line 7.
The R.id requires the XML that will be pasted after the Java code.

@Walizai

This comment has been minimized.

Copy link

commented Jan 30, 2017

Hello dear all,

There is no problem showing in Andriod studio but in mobile it says application failed to start. In XML preview in Andriod it also don't show the display text.

Looking to hear from you guys.

@poltudora

This comment has been minimized.

Copy link

commented Feb 1, 2017

Same problems over here ? Have you figured out what is the issue ?

@gielmuda

This comment has been minimized.

Copy link

commented Feb 4, 2017

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".

@pommereh

This comment has been minimized.

Copy link

commented Feb 5, 2017

I had the problem that display_text_view could not be resolved. After closing the project, opening another one and then opening the PracticeSet2 project again it worked. I assume for some reason it needed some cleanup that is done when making the first gradle built after opening the project

@hoangclick

This comment has been minimized.

Copy link

commented Feb 9, 2017

hi all, after copy code, android studio error: can not resolve symbol "display_text_view"
Please help me!

@panhulio

This comment has been minimized.

Copy link

commented Feb 12, 2017

hi all, after copy code, android studio error: can not resolve symbol "display_text_view"
Please help me!

hey dude, just do what pommereh said. Close the project and open it again. I had the same issue and it seemed to resolve it for some strange reason.

On the side note, can anyone explain what has happened and why does close/open project solves the problem.
Very curious to know!

<3

@auxison

This comment has been minimized.

Copy link

commented Feb 16, 2017

For those with MainActivity in the activity_main.xml showing red, I solved this when I noticed that android was misspelled in the app folders.
I had andriod instead of android. This was not immediately obvious as yoU can imagine and hope it helps somewhat.
I simply modified the first line in the MainActivity.java code to:
package com.example.andriod.practiceset2;

@i-Apoorva

This comment has been minimized.

Copy link

commented Feb 19, 2017

No need to close and reopen the project in case of error: cannot resolve symbol "display_text_view"
Just go to Build->Clean Project

@naptunder

This comment has been minimized.

Copy link

commented Mar 18, 2017

Confused :/

@trickyricky10

This comment has been minimized.

Copy link

commented Mar 21, 2017

display_text_view
display_text_view
display_text_view_2
display_text_view_3

These four keep on showing up as red in the MainActivity :/
Any advice? :)

@ugofred

This comment has been minimized.

Copy link

commented Mar 24, 2017

To solve this, do not change the first line of your code in Mainactivity and also in activity.main
selection_035
selection_034

@rebekaszucs

This comment has been minimized.

Copy link

commented Mar 30, 2017

I could only solve the "can not resolve symbol "display_text_view"" problem by copying in the XML code as well.

@aulakhgurveer

This comment has been minimized.

Copy link

commented Apr 14, 2017

Hi everyone ! I am so annoyed as the application is not working and the main problem which I detected is that the computer can't resolve the 'R' symbol as shown below:
screenshot 5

@endrits079

This comment has been minimized.

Copy link

commented Apr 22, 2017

@aulakhgurveer I have the same problem did you find a solution ?

@DevendraJ

This comment has been minimized.

Copy link

commented May 3, 2017

same problem............

@Micah23

This comment has been minimized.

Copy link

commented May 6, 2017

same problem here have uninstalled the 2.3.1 am am using 2.3 with no problem

@Micah23

This comment has been minimized.

Copy link

commented May 6, 2017

same problem here have uninstalled the 2.3.1 am am using 2.3 with no problem

@Naveedhassan12

This comment has been minimized.

Copy link

commented Jun 6, 2017

I was having the same problem, I cleaned the project and synced project with Gradle file and solved my problem. Thank you! Happy Coding :-)

@ershadak

This comment has been minimized.

Copy link

commented Jul 10, 2017

sketch

line 6 to 10 cannot resolve the values starting with

@priya390

This comment has been minimized.

Copy link

commented Aug 14, 2017

It says 'can not resolve symbol R' and not working..please help me with that

@ausaleh

This comment has been minimized.

Copy link

commented Oct 1, 2017

Go to build. and click rebuild project

@Mradulgoel

This comment has been minimized.

Copy link

commented Nov 18, 2017

11/17 22:59:49: Launching instantapp
Side loading instant app.
Side loading instant app.
Launching deeplink: https://android.example.com/example.

$ adb shell setprop log.tag.AppIndexApi VERBOSE
$ adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d https://android.example.com/example -n "com.google.android.instantapps.supervisor/.UrlHandler"
Unexpected error while executing: am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d https://android.example.com/example -n "com.google.android.instantapps.supervisor/.UrlHandler"
Error while Launching URL

Help me to resolve my above problem.......Please.

@geokapo

This comment has been minimized.

Copy link

commented Nov 20, 2017

if anybody gets wrong on mainactivity.xml and activity_main.xml the red line on tools:context= and on package. The reason is that you have to get the same name for the project at the beggining with activity and mainactivity. For example mine is:

Project name :practiseset2
package com.example.android.practiceset2; ->on mainactivity.xml
tools:context=" com.example.android.practiceset2" ->on activity_main.xml

as you can see the same name "practiseset2" so then you will be just fine!

@Maxwe1

This comment has been minimized.

Copy link

commented Jan 31, 2018

All works for me, thanks a lot.

@tahermahmoud

This comment has been minimized.

Copy link

commented Feb 5, 2018

i didnot get any erorr
but i donot know what to do afteer that
i was past a xml and java codes and no erorr
so. what i should to do?

@abdahma01

This comment has been minimized.

Copy link

commented Feb 13, 2018

Done

@badrddinb

This comment has been minimized.

Copy link

commented Feb 21, 2018

DONE
image

@MMAA1

This comment has been minimized.

Copy link

commented Mar 15, 2018

On my java Mainactivity the TextVier is red!!

@rahulkhatri19

This comment has been minimized.

Copy link

commented Mar 30, 2018

display3(""And look! Box 3!"");
to look like: "And look! Box 3!"

@rahulkhatri19

This comment has been minimized.

Copy link

commented Mar 30, 2018

put this line in : import android.widget.TextView;

@Htewech7

This comment has been minimized.

Copy link

commented Apr 18, 2018

No error Good

@megaunknown

This comment has been minimized.

Copy link

commented May 16, 2018

it works after changing the package name.

@Alihani0almamary

This comment has been minimized.

Copy link

commented May 27, 2018

This is how the code is written

3

@jenoskon

This comment has been minimized.

Copy link

commented Aug 17, 2018

thank you it work for me ``

@shankar-shiv

This comment has been minimized.

Copy link

commented Dec 23, 2018

Do not delete your first line of code !

@rijkerd

This comment has been minimized.

Copy link

commented Jan 12, 2019

Fixed after sync with gradle

@xSurpassionx

This comment has been minimized.

Copy link

commented Jan 24, 2019

I was able to get it work by changing the a few things such as tools:context, and changing the layout from constraint to Linear Vertical. Here is the code .

image

@kabosaif

This comment has been minimized.

Copy link

commented Jun 27, 2019

I did as Pommereh said and the errors have been solved

@xMagicXs

This comment has been minimized.

Copy link

commented Jul 2, 2019

for those with android newer version ignore this line import android.support.v7.app.AppCompatActivity;
and copy from line 12 also paste it there and copy import android.widget.TextView; as well then all should be fine
( the TextView will be red but that because you did not create them in xml yet also this is RelativeLayout and new android is going to generate constraint is why to copy/paste from and to line 12 then you just adapt your xml and you are back in game :) )

@Kelly5978

This comment has been minimized.

Copy link

commented Sep 12, 2019

Okay, why in the world are these examples still listed in the course if they do not work with the newer version? I've now spent way too much time trying to fix this problem....when this is SUPPOSED TO BE A BEGINNER COURSE! I'm guessing no one checks these messages anymore, so I suppose I'm on my own. Very disappointed.

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.