Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Windows 10 android SDK Can't find ID for findViewById(R.id./*insertIdHere*/);

From what I understand, when I create my project, I will have an ID that automatically gets assigned to the activity_main.xml file, but there isn't one. The only place I can find an ID is located in the gradle file, no where else. In this vid, I created the two variables as such:

package com.example.android.funfact;

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

public class MainActivity extends AppCompatActivity {
    private TextView mFactTextView;
    private Button  mShowFactButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mFact = (TextView) findViewById(R.id.);
    }
}

Also just to point out, I know that my current "mFact = (TextView) findViewById(R.id.);" is not complete, it's as it is due to the fact that I can't find the correct ID for it.

when I finish mFactTextView= (TextView) findViewById(R.id./this remains empty/); it does not provide valid autocomplete responses, the responses are the following: all, basic, chains, packed, parent, spread, spread_inside, wrap, class.

None of these are the id I need to get the views to talk to each other, and I feel like there are a ton of people asking the same question but not really understanding the problem.

Things I have tried: re-building the solution, cleaning the solution, reinstalling the f*cking program, restarting my computer, punching children, and eating icecream.

I will post down here my main and Manifest.xml files

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.android.funfact">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Here is my main.xml (xml in my layout folder)

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.funfact.MainActivity">

</android.support.constraint.ConstraintLayout>

1 Answer

K so I figured it out. Just go into your layout.xml, make a new text view, a new button, and give them the ID's you put in your class.