Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointer or InflateException when searching on Google Maps
    primarykey
    data
    text
    <p>I'm a beginner and I'm currently trying to get an experiment working with Google Maps Api V2+fragments+actionbar but I think I'm hitting a wall here. The purpouse of this app is very simple, you type a location from either an edittext on a fragment or an edittext from the actionbar, then when you hit search, the app shows the map with a marker on the wanted location. If I type a search and hit the button I get the following error:</p> <pre><code> 01-10 17:29:06.560: E/AndroidRuntime(17425): FATAL EXCEPTION: main 01-10 17:29:06.560: E/AndroidRuntime(17425): java.lang.NullPointerException 01-10 17:29:06.560: E/AndroidRuntime(17425): at alan.android.testMapas.FragOne$1.onClick(FragOne.java:32) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.view.View.performClick(View.java:3574) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.view.View$PerformClick.run(View.java:14293) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.os.Handler.handleCallback(Handler.java:605) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.os.Handler.dispatchMessage(Handler.java:92) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.os.Looper.loop(Looper.java:137) 01-10 17:29:06.560: E/AndroidRuntime(17425): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-10 17:29:06.560: E/AndroidRuntime(17425): at java.lang.reflect.Method.invokeNative(Native Method) 01-10 17:29:06.560: E/AndroidRuntime(17425): at java.lang.reflect.Method.invoke(Method.java:511) 01-10 17:29:06.560: E/AndroidRuntime(17425): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 01-10 17:29:06.560: E/AndroidRuntime(17425): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 01-10 17:29:06.560: E/AndroidRuntime(17425): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>It only works if the map is already being displayed, but if I change tabs and go back or search again I get an inflate exception:</p> <pre><code>01-10 17:32:26.080: E/AndroidRuntime(17681): FATAL EXCEPTION: main 01-10 17:32:26.080: E/AndroidRuntime(17681): android.view.InflateException: Binary XML file line #2: Error inflating class fragment 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 01-10 17:32:26.080: E/AndroidRuntime(17681): at alan.android.testMapas.FragSearch.onCreateView(FragSearch.java:35) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.os.Handler.handleCallback(Handler.java:605) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.os.Handler.dispatchMessage(Handler.java:92) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.os.Looper.loop(Looper.java:137) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.app.ActivityThread.main(ActivityThread.java:4441) 01-10 17:32:26.080: E/AndroidRuntime(17681): at java.lang.reflect.Method.invokeNative(Native Method) 01-10 17:32:26.080: E/AndroidRuntime(17681): at java.lang.reflect.Method.invoke(Method.java:511) 01-10 17:32:26.080: E/AndroidRuntime(17681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 01-10 17:32:26.080: E/AndroidRuntime(17681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 01-10 17:32:26.080: E/AndroidRuntime(17681): at dalvik.system.NativeStart.main(Native Method) 01-10 17:32:26.080: E/AndroidRuntime(17681): Caused by: java.lang.IllegalArgumentException: Binary XML file line #2: Duplicate id 0x7f040036, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285) 01-10 17:32:26.080: E/AndroidRuntime(17681): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669) 01-10 17:32:26.080: E/AndroidRuntime(17681): ... 18 more </code></pre> <p>Here's the main activity:</p> <pre><code>public class MainActivity extends SherlockFragmentActivity { public ActionBar bar; private EditText txtsearch; // private @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); bar = getSupportActionBar(); //mTabSeeker=new TabSeeker(bar); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayShowTitleEnabled(false); Tab tab0 = bar .newTab() .setText("1") .setTabListener( new SherlockTabListener&lt;FragOne&gt;(this, "One", FragOne.class)); bar.addTab(tab0); Tab tab1 = bar .newTab() .setText("2") .setTabListener( new SherlockTabListener&lt;FragSearch&gt;(this, "Search", FragSearch.class)); bar.addTab(tab1); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getSupportMenuInflater(); inflater.inflate(R.menu.activity_main, (Menu)menu); View v = (View)menu.findItem(R.id.searchoption).getActionView(); txtsearch = (EditText)v.findViewById(R.id.txt_search); txtsearch.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { // TODO Auto-generated method stub FragSearch fs; bar.setSelectedNavigationItem(1); fs = (FragSearch) getSupportFragmentManager().findFragmentByTag("Search"); fs.locateSearch(txtsearch.getText().toString()); return false; } }); return super.onCreateOptionsMenu(menu); } </code></pre> <p>The search Fragment</p> <pre><code>public class FragSearch extends SherlockFragment{ private CameraUpdate camUpd1; private GoogleMap map; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.fragsearch,container,false); map = ((SupportMapFragment)getSherlockActivity().getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); map.setMapType(GoogleMap.MAP_TYPE_NORMAL); return view; } public void locateSearch(String text){ Geocoder geocoder = new Geocoder(getActivity(),Locale.getDefault()); try { List&lt;Address&gt;list= geocoder.getFromLocationName(text, 1); if(list!=null){ Double lat=(Double) list.get(0).getLatitude(); Double lng=(Double)list.get(0).getLongitude(); LatLng ubicacion = new LatLng(lat,lng); CameraPosition camUpd1=new CameraPosition.Builder().target(ubicacion).zoom(16).build(); CameraUpdate camUpd3 = CameraUpdateFactory.newCameraPosition(camUpd1); map.clear(); map.addMarker(new MarkerOptions().position(new LatLng(lat,lng)).title(text)); map.animateCamera(camUpd3); }else{ } } catch (Exception e) { // TODO Auto-generated catch block Toast.makeText(getSherlockActivity(), "Search Error", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } } </code></pre> <p>FragOne.java</p> <pre><code> public class FragOne extends SherlockFragment { private EditText et; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.fragone, container, false); et = (EditText) view.findViewById(R.id.editText1); Button bt = (Button) view.findViewById(R.id.button1); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub FragSearch fb; String text; text = et.getText().toString(); fb = (FragSearch) getSherlockActivity() .getSupportFragmentManager() .findFragmentByTag("Search"); fb.locateSearch(text); } }); return view; } } </code></pre> <p>fragsearch.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/&gt; </code></pre> <p>and search.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;EditText style="@style/Theme.Sherlock.Light.Dialog" android:id="@+id/txt_search" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.67" android:inputType="text" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Thank you all in advance! If need me to post anything from the project just let me know.</p> <p><strong>Edit:</strong> I've updated both logs, I think the nullpointer is given because it has to be instanciated before accessing the locateSearch method, so I think I'll have to find a way to pass the text as an argument and located once it has been instanciated, but as for the InflateExceptioin it looks like I'm gonna have to find another way to inflate that fragment's view since that TabListener is the one I use on other apps with no issues regarding regular fragments. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload