I have a view with a facebook style side bar navigation. On the main view I want to display my map. I have followed Google's tutorial exactly! But I keep running into the error Unable to instantiate android.gms.maps.SupportMapFragment.
I did manage to run this on a plain project but when I merge it with my main project this error pops up:
07-25 13:27:53.778: E/AndroidRuntime(24841):
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment:
make sure class name exists, is public, and has an empty constructor that is public
I tried the answers posted below but the problem persists.
"Error inflating class fragment" with google map
and also this one:
Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2
The reference to the google sdk in project properties is also set.
Here is the class:
public class SlideAnimationThenCallLayout extends FragmentActivity implements AnimationListener {
View menu;
View app;
boolean menuOut = false;
AnimParams animParams = new AnimParams();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_slide_animation_then_call_layout);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.menu);
linearLayout.setOnTouchListener(new OnSwipeTouchListener(){
public void onSwipeRight() {
swipeAnimation();
}
});
RelativeLayout listview3 = (RelativeLayout) findViewById(R.id.relativeLayout1);
listview3.setOnTouchListener(new OnSwipeTouchListener(){
public void onSwipeRight() {
swipeAnimation();
}
public void onSwipeLeft() {
swipeAnimation();
}
});
menu = findViewById(R.id.menu);
app = findViewById(R.id.relativeLayout1);
}
The xml file is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/frame_layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView3"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/action_eating">
</ListView>
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/android_homescreen">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
I don't know what is wrong here now. Any Help would be greatly appreciated.
Judging by you error:
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment:
make sure class name exists, is public, and has an empty constructor that is public
and the fact the SupportManFragment class is part of the google-play-services library, you problem is surtenly in the way you reference this library or the library it self.
I would suggest you to re-download it using the SDK-Manager and move it to a location where it path would be shorter and then try to reference it again using the answer you have in this question:
Error java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in Google Map V2
Right click on project ---> Android Tools ---> Add Support Library.
Download it and clear the project and build again. Hope it will work
Related
I am trying to create an Activity that extends AppCompatActivity and has two fragments inside of it (one below another - just by using a LinearLayout). I would like the first fragment to extend the PreferenceFragmentCompat class from the support-v7 library.
I followed Google's short example regarding PreferenceFragmentCompat as shown at https://developer.android.com/reference/android/support/v7/preference/PreferenceFragmentCompat.html.
Here is my current code:
GroupDetailsActivity.java
public class GroupDetailsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group_details);
GroupDetailsPrefFragment prefFragment = GroupDetailsPrefFragment.newInstance();
GroupDetailsMembersFragment membersFragment = GroupDetailsMembersFragment.newInstance();
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction()
.add(R.id.flPrefFragment, prefFragment, GroupDetailsPrefFragment.TAG)
.add(R.id.flMembersFragment, membersFragment, GroupDetailsMembersFragment.TAG)
.commit();
}
}
GroupDetailsPrefFragment .java - The problematic fragment
public class GroupDetailsPrefFragment extends PreferenceFragmentCompat {
public static final String TAG = "GroupDetailsPrefFragment";
#Override
public void onCreatePreferences(Bundle bundle, String s) {
setPreferencesFromResource(R.xml.group_details_preferences, s);
}
public static GroupDetailsPrefFragment newInstance() {
GroupDetailsPrefFragment fragment = new GroupDetailsPrefFragment();
return fragment;
}
}
GroupDetailsMembersFragment.java - Completely empty for now..
public class GroupDetailsMembersFragment extends Fragment {
public static final String TAG = "GroupDetailsMembersFragment";
public static GroupDetailsMembersFragment newInstance() {
GroupDetailsMembersFragment fragment = new GroupDetailsMembersFragment();
return fragment;
}
}
activity_group_details.xml - Activity's layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/flPrefFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/flMembersFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
group_details_preferences.xml - The preference XML file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="#string/remove_me"
android:key="#string/pref_key_settings_remove_me"/>
<Preference
android:title="#string/delete_group"
android:key="#string/pref_key_settings_delete_group"/>
</PreferenceScreen>
Trying to compile and run the code above lead me into a few errors, the first one was regarding a preference theme that was not set. I have quickly scanned the internet and found you need to add the following line into your Activity's theme : <item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
To do so, I was needed to add the support-v14 library to gradle!
Trying to run the code again, lead me to another error, which is the reason I am posting this, and so far I didn't find any way to solve this issue. Here is the crash log :
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cochat.android/com.cochat.android.ui.groups.details.GroupDetailsActivity}: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list_container' that is not a ViewGroup class
at android.support.v7.preference.PreferenceFragmentCompat.onCreateView(PreferenceFragmentCompat.java:269)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1189)
at android.app.Activity.performStart(Activity.java:5441)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Been stuck on this for a while now, tried looking up different posts on stackoverflow or other websites, seen some solutions, but for some reason none of them managed to solve my problem.
Edit:
My gradle file contains the following:
compileSdkVersion 25
buildToolsVersion '25.0.2'
...
compile 'com.android.support:preference-v7:25.1.0'
compile 'com.android.support:preference-v14:25.1.0'
Update Jan 02 '17
I've been looking into the source code of PreferenceFragmentCompat and seen it is trying to load the following layout: R.layout.preference_list_fragment.
In the onCreateView() method of the class, it is inflating the layout, and trying to look for the id android.R.id.list_container.
The problem is that there is no such id within the layout.
Here is a code snippet from the PreferenceFragmentCompat:
final View view = themedInflater.inflate(mLayoutResId, container, false);
final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
if (!(rawListContainer instanceof ViewGroup)) {
throw new RuntimeException("Content has view with id attribute "
+ "'android.R.id.list_container' that is not a ViewGroup class");
}
While
private int mLayoutResId = R.layout.preference_list_fragment;
Still looking for a solution, thanks!
I got past this using the following bugfix:
https://github.com/Gericop/Android-Support-Preference-V7-Fix
Simple 3 step process is to update the app's build.gradle,
Remove:
compile 'com.android.support:preference-v7:25.0.1'
compile 'com.android.support:preference-v14:25.0.1'
Add
compile 'com.takisoft.fix:preference-v7:25.0.1.0'
Then update your app's theme for preferences to use PreferenceFixTheme
(You're already using PreferenceFragmentCompat so good to go).
UPDATE:
On further investigation, with api 25.1.0, AppCompat worked fine once I realized the very strict restrictions on the style for Preferences.
I found this resource very helpful in getting everything set up nicely:
According to this article:
Note that Google changed the needed id from R.id.list_container (in
revision 23.4.0) to android.R.id.list_container (in revision 24.0.0).
Android Studio says the new id requires API 24, but it also works on
older APIs.
ViewGroup in your layout file (activity_group_details.xml) should have id "#android:id/list_container”. to make it work. It can look like this:
<FrameLayout
android:id="#android:id/list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/flMembersFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
And you have to use this id for your transaction too, note that the other fragment of yours can use any Id for container, only pref is 'special'
So I have found a work around for this, might not be the best, but it is the only thing I have managed to get working! It seems like a problem/bug with the support library..
I have copied the original PreferenceFragmentCompat to a local class, and made minor changed to it. I have replace the following line
private int mLayoutResId = android.support.v7.preference.R.layout.preference_list_fragment;
with
private int mLayoutResId = R.layout.preference_fragment_compat_container;
which is a layout I have made, that it very simple and only contains a container for the list. Here is the layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
Doing the above will allow you to use PreferenceFragmentCompat with the specific gradle settings above (see original post) without any problems.
The down side is that upgrading the support libraries will not upgrade your PreferenceFragmentCompat since it is copied of course. You will need to keep track of the support libraries, and when ever the problem is fixed, you may delete the copied class and use the original one.
If you have any other solutions or ideas please share!
I think you just need to use the support PreferenceScreen and Preferences:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.Preference
android:title="#string/remove_me"
android:key="#string/pref_key_settings_remove_me"/>
<android.support.v7.preference.Preference
android:title="#string/delete_group"
android:key="#string/pref_key_settings_delete_group"/>
</android.support.v7.preference.PreferenceScreen>
Checked out my answer here https://stackoverflow.com/a/53560798/1247248
you need a layout resource with that id
Adding this line to your AppTheme in the styles.xml file should do the trick:
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
I have got an idea to get rid of some coding when we do initializion of views.
When we create an xml layout in android. At that movement same name class is created with UpperCase Letters with a dialogue with permission. And as i created views with ids. It should create Views and initialize them automatically.
for e.g
close.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/closeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/close_img" />
<TextView
android:id="#+id/closeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Testing Text" />
</LinearLayout>
And automatically generated java code should be.
public class Close extends Activity
{
TextView CloseText;
Button CloseBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CloseText = (TextView)findViewById(R.id.closeText);
CloseBtn = (Button)findViewById(R.id.closeBtn);
}
}
I can read xml and do the other stuff as I explained. But how could i add this module to eclipse and How could i create a service which work in Background all the time in eclipse.
Suggest me how to add this module(Plugin) to eclipse and i am going to use JAXB to generate Java Objects from XML document. Is there any better option.
Here in this website i find that just paste the xml and you will get your java code ready for activity class.
i had attached the link
I did everything just as stated in this tutorial:
google android basic tutorial
and despite everything being done just as described, the code refuses to compile with 3 errors. Looks like the guys writing the turorial forgot to mention what are those things and where/how do I define them.
The errors I get:
Error:(24, 68) error: cannot find symbol variable container
Error:(36, 23) error: cannot find symbol variable action_settings
Error:(46, 54) error: cannot find symbol variable fragment_display_message
Neither of the 3 fields are defined anywhere (Perhaps one of the libraries is wrong?)
The file in question is:
package com.example.asteroth.first;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.R;
public class DisplayMessageActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
// setContentView(R.layout.activity_display_message);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}
}
#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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_display_message, container, false);
return rootView;
}
}
}
I am using Android Studio I just downloaded and no question from search or Similar Questions points at the problem like this one, hence I suspect authors of tutorial forgot to mention something minor. I've seen suggestion to place the "container" as a new ID in one of the XML files, but to no avail.
EDIT:
'cannot find symbol ActionBarActivity' following Android Development Tutorial?
This post suggest a solution, however it changes ActionBarActivity to just Activity which is very different from what the tutorial uses and I don't know how serious repercussions would it cause
EDIT2:
Problems found and removed:
import android.R //causes action_settings error
container missing //had to add it in the xml file as an id
xml file named wrong //If I got that correctly, I'm still waiting for someone experienced to clarify, but seems like the tutorial used different name for the xml file then the one that the java code references
Remaining problem is similar to this one
Cannot resolve method placeholderfragment error
however, I both extend Fragment and include android.app.Fragment as can be seen in the included file.
I tried the same tutorial and here is how I fixed my errors:
R.id.container cannot be resolved error
I had to import android.support.v4.app.Fragment to fix this problem and add android:id = "#+id/container" to the RelativeLayout section in my activity_display_message.xml file.
fragment_display_message cannot be resolved error
Change R.layout.fragment_display_message to R.layout.activity_display_message instead. There is no need for creating a new xml file for fragment_display_message.
This should fix these two errors.
But you would probably be better off if you comment out the if(savedInstanceState............ statement as otherwise your program would crash once you try to run it if it doesn't give you any errors.
Your onCreate method should look like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_display_message);
Intent intent=getIntent();
String message=intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
TextView textView=new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
/*if (savedInstanceState==null){
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}*/
}
I'm doing the tutorial for the first time now on Feb. 23, 2015 and ran into this compilation error though I feel like I've closely followed the steps. I changed fragment_display_message to activity_display_message which is an XML file they have us create in the tutorial. This seems to solve the error, and allow the app to run.
// A placeholder fragment containing a simple view.
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_display_message,
container, false);
return rootView;
}
}
Add this line to take care of your first error: android:id = "#+id/container"
You get that error because container isn't in the XML.
Add <string name="action_settings">Action Settings</string>so that the "Action settings" which I'm assuming doesn't exist in your XML code since you have that error.
Create your own XML file with this exact name fragment_display_message.xmlto handle that error and check what code you might need to insert into it in your google tutorial. Often times with Eclipse, these files are not included for reasons outside my knowledge. So you have to create them or insert them yourself. (Make sure you have the latest version of the SDK by the way.
EDIT: Be sure to have the correct imports matching with your "tutorial". I took a gander at it and see you missing two imports. One of which another user answered.
It's a copy paste error.
If you paste code with "R." in it, the development environment always imports the android.R:
import android.R;
If you use R.id.... it is always looking up the android.R and not your own generated R class.
Delete the import and it should be fine. This general works for me.
After that you have to check if you already defined the id's and layout.
You can check Layouts by looking on the package explorer under res->layout. In your example there has to be an fragment_display_message.xml in it.
For id's you have to look up all of your layouts and check if there are the specific views like the container.
I got a similar error on the Building a Simple User Interface step:
Error:(18, 54) error: cannot find symbol variable toolbar
I've narrowed the cause down to res/layout/activity_my.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="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
The original version that did compile (but no button or text box) is:
<?xml version="1.0" encoding="utf-8"?>
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" android:fitsSystemWindows="true"
tools:context=".MyActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_my" />
<android.support.design.widget.FloatingActionButton android:id="#+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
fragment_display_message
Make sure you have a file named fragment_display_message.xml in your res/layout folder.
action_settings
Make sure you have that item in your menu.xml file in res/menu
<menu 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"
tools:context=
".MenuExampleActivity" >
<item
android:id="#+id/action_settings"
android:orderInCategory="1"
app:showAsAction="never"
android:title="My menu option"/>
</menu>
container
Make sure you have a layout (ex. RelativeLayout) with the id set to "container" in your activity_main.xml file in res/layout, given that it's the reference for the code to insert the fragment there.
I am using the library WizardDroid which uses android.support.v4.app.Fragment internally.
In my application I use normal Fragments though (android.app.Fragment).
I also use Google Maps v2, which I retrieve in a fragment that inherits from a wizardroid class (which itself inherits from android.support.v4.app.Fragment).
public class CreateEventStepMap extends WizardStep
{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.create_event_map, container, false);
final Event event = ((EventInfo)getActivity()).getEvent();
final GoogleMap googleMap = ((com.google.android.gms.maps.SupportMapFragment)getActivity().getFragmentManager().findFragmentById(R.id.map)).getMap();
return v;
}
}
So as you can see, I cast to com.google.android.gms.maps.SupportMapFragment() because findFragmentById(R.id.map) returns a support map fragment. I cannot do otherwise because I would get a compilation error.
This is the XML that the map fragment is inside:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Everywhere else in my application I use normal fragments!
When I run the application I get this exception:
11-08 20:47:19.178: E/AndroidRuntime(10347): android.view.InflateException: Binary XML file line #8: Error inflating class fragment
Is this because I am mixing Fragments and support map fragments in the same application or maybe I am doing something else stupid?
If the answer is the first, would a solution be to change the code of the wizardroid library (I don't need support for versions < 4) ?
Warning: Noob alert.
I am very new to both Android and OSM. All I want is a map to display.
Google's MapView can be the root of main.xml, can OSM's MapView be root as well?
Here is my current main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.osmdroid.views.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
tilesource="MapquestOSM" />
</LinearLayout>
Here is my Activity:
public class AndroidManiTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.id.map);
}
}
I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anny/com.anny.AndroidManiTestActivity}:
Android.content.res.Resources$NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid
EDIT:
I am running osmdroid 3.0.8 and slf4j 1.5.8.
Your setContentView(.. ) needs to take a .layout argument not a .id, so it's
setContentView(R.layout.main);
after that you can then refer to the .map with a line such as:
findViewById(R.id.map);