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 Build a Simple Android App (retired 2014) Getting Started with Android Introduction to Methods and Classes

Joshua Friedman
Joshua Friedman
537 Points

Intellisense not working?

I'm hovering my cursor over "setContentView" in order to get intellisense to work, but it's not working the same way as it is in the video. When I hover over "setContentView," my yellow box says "note: this element neither has attached source nor attached javadoc and hence no javadoc could be found." I downloaded this file as a full OSX package from teamtreehouse, and am currently running it on a 2008 Macbook with SnowLeopard.

My MainActivity.java code also differs from that of the video. Mine looks like this

package com.example.crystalball;

import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

Can someone please enlighten me as to where the error is?

Thank you!

21 Answers

Joshua Friedman
Joshua Friedman
537 Points

So I deleted everything, reloaded it from scratch, followed all of Ben's instuctions and now it works! Error must've been somewhere between chair and the keyboard (^_^). Thank you both for all your help, though!

I don't think there's a problem here.

Hovering over setContentView will give you something like void anroid.support.v7.app.ActionBarActivity.setContentView(int layoutResId) - that's fine; the note below about no Javadoc is about the import, not your code and you shouldn't worry about it. I don't know what the video suggests you should see.

Try hovering over something more local ... like onCreateOptionsMenu(Menu menu) - this should give you a more verbose explanation.

Whilst typing code, try pressing Ctrl+Space to bring up Intellisense; that works well.

The different code you're seeing is probably more to do with the video being outdated by the latest Eclipse release. What are the specific code differences that are concerning you?

Steve.

Joshua Friedman
Joshua Friedman
537 Points

I cannot do some of the processes that Ben does in the video. For example, when I try to cast textview as Ben does in stage one, I get no options to do so, even if I use the ctrl+space bar method. I can't tell if I did something wrong in installing this, or if there is an easy solution to my problem. As a beginner in Java I find this type of situation to be incredibly frustrating.

Before I look at the video, there's another thread that might help. Give that a try and see if it works for you, if not, I'll watch the video and we can work out what's going on.

I know it can be frustrating when the workings don't work - stick with it, there's loads of people who can help!

Steve.

Link to thread

Joshua Friedman
Joshua Friedman
537 Points

I looked at the other threads earlier and tried their solutions: no luck.

FWIW the video in question is "Accessing Views in Code"

OK - I've watched the video up to the point where we're adding the textView1 with findViewById(R.id.textView1); - did Intellisense work when typing the R. and then R.id.?

I'm now at the point where that line is complete but needs a cast to clear the compiler; hovering over the red line (you've got a red line, right?) gives me the suggested quick fixes and confirms the type mismatch. I'm guessing you're not seeing that, right?

Do you get a red cross & a lightbulb in the gutter on the left margin? Does hovering over that and clicking do anything? And have you organised your imports?

Joshua Friedman
Joshua Friedman
537 Points

I did.

I can enter R. I can enter R.id. but among the list I do NOT see an option labelled textview.

I also have significantly more options in my list. None of them refer to Button or Textview.

I get a long list too - not just my local project IDs. Mine starts with action_bar etc.

If you type R.id.t do you not get left with 5 options ... tabMode, textView1, title, top_action_bar and this?

Joshua Friedman
Joshua Friedman
537 Points

I only get tabMode, title, top_action_bar, and this.

I do NOT get textView1.

I'm going to delete all and see if reinstalling helps.

There's a problem with your .xml file, then. Intellisense is working, but the ID isn't assigned properly.

Can you copy the content of activity_main.xml - it should have the lines:

<textView
    android:id="@+id/textView1"
    android:text="TextView" />

Among others!

Intellisense can't see that ID so doesn't know there's a type mismatch for the FindViewById - once Intellisense sees that textView1 is a TextView, it'll know that a cast is required.

Look at your XML before deleting - this is an in-code issue, not an installation problem.

I see two situations for this error

Fix 1
Imgur

Go to Eclipse -> Preferences -> Java -> Compiler -> Javadoc -- and make sure the option process javadoc Comments is checked

Fix 2
Download the Android Documentation if you have'nt

Once you start using Android, it overrides the default Java documentation

Hope this helps

Joshua Friedman
Joshua Friedman
537 Points

Gunjeet: I tried option one and it's still not working. Where can I find the Android Documentation and install it?

Steve: Here is a copy of my activity_main.xml file. I can find the bits about textview but I still can't get those methods to work.

<p><RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.crystalball.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:textSize="32sp" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:text="Enlighten me!" />

</RelativeLayout> ```

Even with the above code, I STILL cannot access TextView1 when I enter "R.id.t" As far as I know I've done everything here right so why it's not working is beyond me.

Android documentation is included in the SDK manager. Just make sure you've download them with the SDK, Samples and other files for that particular API.

The first line in your xml has a <p> tag . Get rid of that that and now try and locate textView1 from R resource. (Just a wild shot)

Joshua Friedman
Joshua Friedman
537 Points

Gunjeet: When you say "tag," do mean that <p> at the top? Even when I get rid of that, I see nothing. I also can't find anything about textview in the R file

Oh the markdown must have removed that.

I meant remove the <p*>* tag in the beginning of the xml file. Also I don't see a closing Relative Layout tag. I hope you've added that too.

This is how your xml should look like, with opening and closing tags for Relative Layout

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.crystalball.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:textSize="32sp" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:text="Enlighten me!" />

</RelativeLayout>
Joshua Friedman
Joshua Friedman
537 Points

Gunjeet:

Way ahead of you. Still no results :(

I just edited my comment above. Did you add the closing relative layout tag in the end

Joshua Friedman
Joshua Friedman
537 Points

Yes. It's there. I don't know why but no matter what if I try to paste code on here it doesn't show up with correct formatting.

Did you try creating a project from scratch again.? It's very unlikely for this to happen. If I do find some other solution i'll get back to you.

Joshua Friedman
Joshua Friedman
537 Points

I did once, but I'll try it again later.

Thanks for your help!

Glad you got it sorted! :-)

Steve.