Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"MapFragment cannot be resolved to a type" even though I am on API level 17

I just started using MapFragments, and I can get the Map to show in my Activity. I just use a simple XML-layout, and it works as expected:

enter image description here

Now, I need to get the Fragment in code, so I can start interacting with the Map. This is where I run into problems:

enter image description here

As you can see, the MapFragment (or getFragmentManager) cannot be resolved to a type. I am targeting Android 4, API level 17:

enter image description here

and you can also see that I am referencing the Googke Play library.

Here is the Manifest, just for clarity:

enter image description here

So, the big question is: why can't I resolve MapFragment? What am I missing?

As a side note: SupportMapFragment seems to resolve OK, but that's not what I want.

like image 984
Ted Avatar asked Jan 18 '13 20:01

Ted


1 Answers

To use MapFragment, you need the Android library project attached to your app (as you had) and the import statement for com.google.android.gms.maps.MapFragment. Based on your comments, the latter part was the issue.

Usually, Eclipse suggest to import it by itself, so I never thought of doing it manually.

I have run into that problem on occasion as well, where -- steadfastly refuses to add an import. I have not been able to come up with a reproducible scenario, and it happens infrequently enough that I just shrug, add it manually, and move along to other things. I'm also uncertain whether the problem is with Eclipse or with any ADT extensions to the import resolver.

Besides, I went without Eclipse for a long time in Android development, typing in import statements manually, and so I'm kinda used to it.

Btw, you answer a lot of questions here on SO, do you have time for anything else? ;-)

I am a fast typist, courtesy of several years as a teenager typing on a manual typewriter.

(For you young'uns reading this, a "typewriter" was basically a keyboard directly connected to a printer, and a "manual typewriter" was one that use the mechanical action of pressing the keys to actually put the letters on the paper, and therefore worked without electricity. Also, you are cordially invited to get off my lawn.)

like image 97
CommonsWare Avatar answered Nov 19 '22 09:11

CommonsWare