android


How to solve an instantiate the map fragment error?


public class OpenMapforLocating extends FragmentActivity implements OnMapClickListener,OnMapLongClickListener,OnMarkerDragListener {
public GoogleMap myMap;
Location myLocation;
LatLng currentlatlon;
String currentLocaiton;
final int RQS_GooglePlayServices = 1;
boolean markerClicked;
PolygonOptions polygonOptions;
Polygon polygon;
Button btn_selected;
EditText txt_selectedLocaiton;
String SelectioType;
SharedPreferences prefrences;
public static final String PREFS_NAME = "STPL_BOOKING_DETAILS";
SharedPreferences prefrencesFaviourtes;
public static final String PREFS_FAV = "STPL_BOOKING_FAVIOURTE_LIST";
/** Called when the activity is first created. */
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.openmapview);
Bundle extras = getIntent().getExtras();
SelectioType = extras.getString("SelectionType");
Log.d("SelectionActivity", "selection Type"+SelectioType);
txt_selectedLocaiton =(EditText)findViewById(R.id.editlocation);
btn_selected =(Button)findViewById(R.id.btn_selectedLocation);
btn_selected.setOnClickListener(onclickListner);
android.app.FragmentManager myFragmentManager = getFragmentManager();
MapFragment myMapFragment
= (MapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = myMapFragment.getMap();
myMap.setMyLocationEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setOnMapClickListener(this);
myMap.setOnMapLongClickListener(this);
myMap.setOnMarkerDragListener(this);
myMap.setTrafficEnabled(false);
myMap.setMyLocationEnabled(true);
markerClicked = false;
LatLng myPoint= new LatLng(gpsdataElements.latitude, gpsdataElements.logitude);
Log.d("OpenMapFOrLocation",gpsdataElements.latitude+" "+gpsdataElements.logitude);
myMap.addMarker(new MarkerOptions().title("mylocation").position(myPoint).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).draggable(true));
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPoint, 15));
// Zoom in, animating the camera.
myMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* #see android.app.Activity#onDestroy()
*/
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
/* (non-Javadoc)
* #see android.app.Activity#onPause()
*/
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
/* (non-Javadoc)
* #see android.app.Activity#onRestart()
*/
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
private OnClickListener onclickListner = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_selectedLocation:
prefrences= getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = prefrences.edit();
if(SelectioType.contains("FromAddress"))
{
Constants.pickupLat=currentlatlon.latitude;
Constants.pickupLon=currentlatlon.longitude;
editor.putString("PickupLocation",txt_selectedLocaiton.getText().toString());
}
else if(SelectioType.contains("ToAddress"))
{
Constants.dropLat=currentlatlon.latitude;
Constants.droplon=currentlatlon.longitude;
editor.putString("DropLocation",txt_selectedLocaiton.getText().toString());
}
editor.commit();
finish();
break;
default:
break;
}
}
};
#Override
protected void onResume() {
super.onResume();
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
// Toast.makeText(getApplicationContext(),
// "isGooglePlayServicesAvailable SUCCESS",
// Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
}
}
#Override
public void onMarkerDrag(Marker marker) {
// TODO Auto-generated method stub
}
#Override
public void onMarkerDragEnd(Marker marker) {
// TODO Auto-generated method stub
}
#Override
public void onMarkerDragStart(Marker marker) {
// TODO Auto-generated method stub
}
#Override
public void onMapLongClick(LatLng point) {
// TODO Auto-generated method stub
}
#Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
myMap.clear();
currentlatlon =point;
// Toast.makeText(getBaseContext(), point.latitude +" "+point.longitude, Toast.LENGTH_SHORT).show();
markerClicked = false;
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
StringBuilder strReturnedAddress = new StringBuilder("");
//
try {
List<Address> addresses = geocoder.getFromLocation(point.latitude, point.longitude, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
txt_selectedLocaiton.setText(strReturnedAddress.toString());
currentLocaiton=strReturnedAddress.toString();
}
else{
txt_selectedLocaiton.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
txt_selectedLocaiton.setText("Canont get Address!");
}
myMap.addMarker(new MarkerOptions().title("mylocation").position(point).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).draggable(true));
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 15));
// Zoom in, animating the camera.
myMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.mapmenu, menu);
return true;
}
/**
* Event Handling for Individual menu item selected
* Identify single menu item by it's id
* */
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_myfaviourts:
// Single menu item is selected do something
// Ex: launching new activity/screen or show alert message
prefrencesFaviourtes= getSharedPreferences(PREFS_FAV, 0);
String oldFaviouteLoc=prefrencesFaviourtes.getString("myFaviourteLocation", "");
prefrencesFaviourtes= getSharedPreferences(PREFS_FAV, 0);
SharedPreferences.Editor favEditor = prefrencesFaviourtes.edit();
favEditor.putString("myFaviourteLocation", oldFaviouteLoc+"!"+currentLocaiton+"$"+currentlatlon.latitude+"$"+currentlatlon.longitude+"!");
favEditor.commit();
Toast.makeText(OpenMapforLocating.this, "New Favioute saved...", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_enableTraffic:
Toast.makeText(OpenMapforLocating.this, "Save is Selected", Toast.LENGTH_SHORT).show();
myMap.setTrafficEnabled(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
openmapview.xml layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/editlocation"
android:background="#color/Gray"
android:textColor="#color/White"
android:hint="select location"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_selectedLocation"
android:layout_below="#+id/editlocation"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/map"
>
</LinearLayout>
<Button
android:id="#+id/btn_selectedLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/rounded_edittext1"
android:text="ok" />
</RelativeLayout>
LogCat
08-23 15:08:49.330: E/AndroidRuntime(430): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stpl.fasttrackbooking/com.stpl.fasttrackbooking.OpenMapforLocating}: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.os.Looper.loop(Looper.java:123)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-23 15:08:49.330: E/AndroidRuntime(430): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 15:08:49.330: E/AndroidRuntime(430): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 15:08:49.330: E/AndroidRuntime(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-23 15:08:49.330: E/AndroidRuntime(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-23 15:08:49.330: E/AndroidRuntime(430): at dalvik.system.NativeStart.main(Native Method)
08-23 15:08:49.330: E/AndroidRuntime(430): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-23 15:08:49.330: E/AndroidRuntime(430): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.Activity.setContentView(Activity.java:1647)
08-23 15:08:49.330: E/AndroidRuntime(430): at com.stpl.fasttrackbooking.OpenMapforLocating.onCreate(OpenMapforLocating.java:88)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-23 15:08:49.330: E/AndroidRuntime(430): ... 11 more
08-23 15:08:49.330: E/AndroidRuntime(430): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-23 15:08:49.330: E/AndroidRuntime(430): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
08-23 15:08:49.330: E/AndroidRuntime(430): ... 20 more
08-23 15:08:49.330: E/AndroidRuntime(430): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.stpl.fasttrackbooking-1.apk]
08-23 15:08:49.330: E/AndroidRuntime(430): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-23 15:08:49.330: E/AndroidRuntime(430): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-23 15:08:49.330: E/AndroidRuntime(430): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-23 15:08:49.330: E/AndroidRuntime(430): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
This code works well in large and medium screen. I was try to modify this code to work in small screen. so that i created layout-small folder under res and ran this code. When click on the "place using map" option then the above error was occurred. I don't know which part of the code causes this kind of error. Where can i do the changes in the code.Help me friends.
In OnCreate you can get an error.
myMap = myMapFragment.getMap();
check this answer.
And after getMap. Check your map and only the do something with it: setting markers etc.
And check your layout at line 14:
Caused by: android.view.InflateException: **Binary XML file line #14**: Error inflating class fragment
EDIT
try to edit your fragment like this:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="com.google.android.gms.maps.MapFragment"
/>

Related Links

How do I add elevation (shadow) to my BottomNavigationView. It doesn't come by default
Xamarin : extract sqlite to a folder in my device
Align a RelativeLayout inside a RecyclerView to the right
am instrument FAILED BINDER TRANSACTION
Verify if user has account in my app with iCloud auth approach
Retrofit is not working in android
Android - working with a BottomSheet in a Fragment
onAnimationUpdate: height does not change after device is rotated
Cast Session terminates with error code 2005
Change the background of a CollapsingToolabarLayout
Google Sign-In Failed Android
code to enable a setting of Android developer mode [duplicate]
Error while inserting values in db [duplicate]
How to use libjpeg-turbo to decode JPEG9 Image?
Play .mov Video file in Android
Is there a way to give a List to a Fragment from just a java class (Not an activity or fragment)

Categories

HOME
prism
cheerio
gpu
google-spreadsheet
powerpoint
camera
obfuscation
oracle-apex-5
r-googlesheets
bitbucket-api
google-cloud-functions
xbee
crystal-lang
okhttp
little-proxy
heap
speech-synthesis
plink
esoteric-languages
powershell-v5.0
mathprog
dimensional-modeling
jmp
delphi-xe5
microsoft-ocr
springfox
cgbitmapcontext
dpdk
licensing
jackson-modules
intersystems-cache
sammy.js
mnist
numpy-broadcasting
apic
c9.io
signals-slots
trigonometry
android-softkeyboard
android-ibeacon
dbnull
sharp-snmp
microsoft-metro
outputcache
vaadin-elements
dotnet-httpclient
compiler-design
java-6
avx
otp
pybrain
cmp
change-tracking
pytables
meteor-packages
pacemaker
microstation
piracy-prevention
themoviedb-api
avisynth
roadkill-wiki
forwarding
finalbuilder
vacuum
jsvc
google-refine
gamekit
angular-gettext
formview
appserver
device-tree
live555
dsym
gwt-openlayers
mysql-error-1044
isqlquery
facebook-timeline
swfobject
asplinkbutton
pdfviewer
cuda-gdb
inkcanvas
oracle-enterprise-linux
role
landscape-portrait
automationelement
inline-formset
ie-compatibility-mode
binomial-heap
interprocess
filesystemobject
strtod
silverlight-oob
purepdf
contentpresenter
image-capture

Resources

Encrypt Message