Reputation: 179
I know this title doesn't make sense. The issue is I have a master activity that extends ActionBarActivity (it contains all the code that is shared in all activities); I have another activity that extends the master activity; this last activity contains a map fragment; I added all the required code and I am getting an error on the set content view.
Can someone help? What can I add to help you understand my problem?
EDIT:
Here's the code. I left out many things that I think are irrelevant.
MainLayoutActivity.java:
public class MainLayoutActivity extends ActionBarActivity {
@Override
public void setContentView(int id) {
LinearLayout linearLayoutContent = (LinearLayout) findViewById(R.id.linearLayoutContent);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(id, linearLayoutContent); //linrstlayoutcontent is the linearlayout that will contain the content
}
}
activity_main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayoutMenu"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/frameLayoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgColor"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</FrameLayout>
<ListView
android:id="@+id/MainMenu"
style="@style/MainMenu"
android:background="@color/LeftMenuBackground"
android:divider="@drawable/menu_separator" />
</android.support.v4.widget.DrawerLayout>
ClubDetailsActivity.Java
public class ClubDetailsActivity extends MainLayoutActivity {
private GoogleMap googleMap = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_club_details);
initilizeMap();
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//googleMap = (My_Layout.findViewById(R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
showToast("Sorry! unable to create maps");
}
}
}
}
activity_club_details.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="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:background="@color/white"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Error:
05-19 19:30:50.961: E/AndroidRuntime(20934): FATAL EXCEPTION: main
05-19 19:30:50.961: E/AndroidRuntime(20934): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.borninteractive.fitnesstime/com.borninteractive.fitnesstime.ClubDetailsActivity}: android.view.InflateException: Binary XML file line #164: Error inflating class fragment
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.access$700(ActivityThread.java:154)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.os.Looper.loop(Looper.java:137)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.main(ActivityThread.java:5306)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.reflect.Method.invoke(Method.java:511)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-19 19:30:50.961: E/AndroidRuntime(20934): at dalvik.system.NativeStart.main(Native Method)
05-19 19:30:50.961: E/AndroidRuntime(20934): Caused by: android.view.InflateException: Binary XML file line #164: Error inflating class fragment
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.borninteractive.fitnesstime.MainLayoutActivity.setContentView(MainLayoutActivity.java:237)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.borninteractive.fitnesstime.ClubDetailsActivity.onCreate(ClubDetailsActivity.java:87)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.Activity.performCreate(Activity.java:5255)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
05-19 19:30:50.961: E/AndroidRuntime(20934): ... 11 more
05-19 19:30:50.961: E/AndroidRuntime(20934): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.fragment" on path: /data/app/com.borninteractive.fitnesstime-2.apk
05-19 19:30:50.961: E/AndroidRuntime(20934): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createView(LayoutInflater.java:558)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:649)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-19 19:30:50.961: E/AndroidRuntime(20934): ... 23 more
Thank You
Upvotes: 3
Views: 499
Reputation: 348
Google map v2 is always extend by Fragment activity, because of in xml layout file map portion is displayed by fragment. So you should use extend the Fragment Activity for google map. Please check following link for description of google map v2: https://developers.google.com/maps/documentation/android/start
Upvotes: 1
Reputation: 558
Update your Google Play Library from your sdk manager.
private void checkForMap() {
try {
// Getting Google Play availability status
int status = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(mContext);
// Showing status
if (status != ConnectionResult.SUCCESS) {
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
this, requestCode);
dialog.show();
} else { // Google Play Services are available
// Getting reference to the SupportMapFragment of
// activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
// map = ((MapFragment)
// getFragmentManager().findFragmentById(R.id.map)).getMap();
// Getting GoogleMap object from the fragment
googleMap = fm.getMap();
}
googleMap.setOnInfoWindowClickListener(this);
} catch (Exception exception) {
DebugHelper.printException(exception);
}
}
Upvotes: 1
Reputation: 9103
I am not sure why you get ClassNotFoundException. It seems that support-library is missing in your build. Double check with this page http://developer.android.com/tools/support-library/setup.html#libs-with-res if your build path is set properly. Also check if you are not mixing fragments from support-library with native fragments.
Beside that, even if you fix ClassNotFoundException
your app will not work. in MainLayoutActivity setContentView
you are missing to call super.setContentView(R.layout.activity_main_activity.xml)
;
At the moment linearLayoutContent
will be always null because layout is not setup.
Upvotes: 1