Error inflating class org.mapsforge.map.android.view.MapView

1,354 views
Skip to first unread message

vklein

unread,
Mar 4, 2014, 5:12:35 PM3/4/14
to mapsfo...@googlegroups.com
Hi,

I have tried to build a testapp like the BasicMapViewer with Eclipse.
The code is only a copy of the BasiscMapViewer from the samples.
As pointed out by Emux  in the long Building rescue thread I put mapsforge-core-0.4.0-SNAPSHOT.jar, mapsforge-map-0.4.0-SNAPSHOT.jar,  mapsforge-map-android-0.4.0-SNAPSHOT.jar and mapsforge-map-reader-0.4.0-SNAPSHOT.jar in the libs directory. The neccessary resources are in the right place.
I downloaded the jars on 2014-02-19 from the jenkins-server.

Problem: The app compiles fine but it crashed when the mapView is created.
In the old times I used the mapsforge030-with-dependencies.

/**
     * @return the layout to be used
     */

   
protected int getLayoutId() {
       
return R.layout.mapviewer;
   
}

protected MapView getMapView() {
       
// in this example the mapview is defined in the layout file
       
// mapviewer.xml
        setContentView
(getLayoutId());
       
return (MapView) findViewById(R.id.mapView);
   
}

03-04 22:34:43.244: E/AndroidRuntime(5222): Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class org.mapsforge.map.android.view.MapView
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at android.app.Activity.setContentView(Activity.java:1835)
03-04 22:34:43.244: E/AndroidRuntime(5222):     at org.openseamap.oseamandroidviewer.BasicMapViewer.getMapView(BasicMapViewer.java:221)

and a lot of  more errors



I wonder, as I build a swingmapviewer app with the appropriate libraries mapsforge-core-0.4.0-SNAPSHOT.jar, mapsforge-map-0.4.0-SNAPSHOT.jar,  mapsforge-map-awt-0.4.0-SNAPSHOT.jar and mapsforge-map-reader-0.4.0-SNAPSHOT.jar.
This works fine.

any suggestions?

regards

Victor



emux

unread,
Mar 5, 2014, 3:10:00 AM3/5/14
to mapsfo...@googlegroups.com
Apparently you're following the BasicMapViewerXml example.
Can you write also the mapviewer.xml layout file you use?

Best regards, Emux
Cruiser - Cruiser Beta
Atlas - Atlas Beta

Ludwig

unread,
Mar 5, 2014, 3:11:48 AM3/5/14
to mapsfo...@googlegroups.com
I would actually think it is the usual problem of the mapsforge-map-android jar not being exported in the build. 


--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/e52e3cf3-1286-42aa-8846-0e3c08c9a417%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

vklein

unread,
Mar 5, 2014, 3:30:07 AM3/5/14
to mapsfo...@googlegroups.com
For the first try used the
protected MapView getMapView() {
       
MapView mv = new MapView(this);
        setContentView
(mv);
       
return mv;

but it crashed.

Then I tried the xml version
protected MapView getMapView() {
       
// in this example the mapview is defined in the layout file
       
// mapviewer.xml
        setContentView
(getLayoutId());
       
return (MapView) findViewById(R.id.mapView);
   
}

the mapviewer xml is a copy of the original one
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
android:id="@+id/mainView" android:layout_width="fill_parent" android:layout_height="fill_parent">
   
<org.mapsforge.map.android.view.MapView android:id="@+id/mapView"
       
android:layout_width="fill_parent" android:layout_height="fill_parent" />
   
<TextView android:id="@+id/attribution" android:layout_width="fill_parent"
       
android:layout_alignParentBottom="true"
       
android:layout_alignParentLeft="true"
       
android:text="@string/copyright_osm"
       
android:textColor="#000"
       
android:textSize="4pt"
       
android:layout_marginBottom="1dip"
       
android:singleLine="true"
       
android:layout_height="10dip"
       
android:layout_marginLeft="5dip"
       
android:visibility="visible"/>
</RelativeLayout>

There is a hint from Ludwig that the android.jar is not exported to the build.

any hints to a sulution ?

regards

Victor

emux

unread,
Mar 5, 2014, 3:51:25 AM3/5/14
to mapsfo...@googlegroups.com
Having used Eclipse for development, I simply make a new Android project,
add libraries jars under libs folder and all run fine since then.
I never needed to define export specific items at build (using default settings).
But I understand that IDEs at our days are behemoths with a lot of options
to achieve the same thing (and many can break if someone change an option).

Victor can you check at you project's build window at 'Order and Export' tab
if you have checked the 'Android Private Libraries' (where jars are) and 'Android Dependencies' ?


Best regards, Emux
Cruiser - Cruiser Beta
Atlas - Atlas Beta


vklein

unread,
Mar 5, 2014, 4:23:08 AM3/5/14
to mapsfo...@googlegroups.com
Hi Emux,
I checked the Java Build Path Order and Export and had a closer look on other project-settings that works.
There are no specific differences.
The Android private Libraries tab shows mapsforge map-android, map-reader, core and map.
In the Order and Export tab Android Private Libraries and Android Dependencies are marked.
This is the content of the .classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
   
<classpathentry kind="src" path="src"/>
   
<classpathentry kind="src" path="gen"/>
   
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
   
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
   
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
   
<classpathentry kind="output" path="bin/classes"/>
</classpath>

I did  the way you described, as this was the easies way for me to get some testcode working in an known developement

regards

Victor

emux

unread,
Mar 5, 2014, 4:54:04 AM3/5/14
to mapsfo...@googlegroups.com
I have exactly the same .classpath file.

I've tried something different.
Using Eclipse I made a new 'Android Project from Existing Code' using the Samples app src.
At the libs folder I added the following jars:
android-support-v4.jar
mapsforge-core-0.4.0-SNAPSHOT.jar
mapsforge-map-0.4.0-SNAPSHOT.jar
mapsforge-map-android-0.4.0-SNAPSHOT.jar
mapsforge-map-reader-0.4.0-SNAPSHOT.jar
svg-android-1.0.jar

I did not change anything at classpath or the export tabs.
The Samples app runs fine, both BasicMapViewer and BasicMapViewerXml classes.

So are you sure your Eclipse configuration is unharmed?
Are you using the latest ADT?
Maybe if you start Eclipse with a new clean initialized workbench just to make a test?


Best regards, Emux
Cruiser - Cruiser Beta
Atlas - Atlas Beta


vklein

unread,
Mar 5, 2014, 7:53:42 AM3/5/14
to mapsfo...@googlegroups.com
Hi Emux,

I report success.
Made a new user, got a new kepler eclipse, imported the Samples app src.
I imported only the Samples, not the four builds beneath.
I marked copy projects into workspace. This is essential, otherwise the studio project is damaged.

made a libs folder and importet the jars
android-support-v4.jar
mapsforge-core-0.4.0-SNAPSHOT.jar
mapsforge-map-0.4.0-SNAPSHOT.jar
mapsforge-map-android-0.4.0-SNAPSHOT.jar
mapsforge-map-reader-0.4.0-SNAPSHOT.jar
svg-android-1.0.jar

had to refactor the package name, the imported was main.java.org.mapsforge.... to org.mapsforge.application.android.sample
throw out the test  sources and the test package.

Now it works, thank you for the help,


best regards

Victor

vklein

unread,
Mar 19, 2014, 9:41:55 PM3/19/14
to mapsfo...@googlegroups.com
 Hi Ludwig,

I got a reproducable solution after a longer time.

The problem was that the AndroidGraphicsFactory was not properly setup , so the inflate of the views failed.
In the Sample project this is done in the SamplesApplication

If I create a new project in Eclipse  (Kepler and Helios) the manifest is created with

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.rotateviewbasicmapviewer.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
      <activity android:name=".BasicMapViewer" android:label="BasicMapViewer" />
      <activity android:name=".BasicMapViewerCompassDemo" android:label="BasicMapViewerCompassDemo" />  
    </application>

Usually there is not application file, but the samples project uses this feature.
.
To execute the code in MainApplication.onCreate() or SamplesApplication.onCreate()
there must be an entry android:name=".MainApplication"  or android:name=".SamplesApplication" in the <application> section.


Otherwise onCreate() in the MainApplication is not executed and the factory is not initialized.

regards

Victor



emux

unread,
Mar 20, 2014, 3:17:52 AM3/20/14
to mapsfo...@googlegroups.com
Yes at Android we have to initialize AndroidGraphicFactory with AndroidGraphicFactory.createInstance()
so that DisplayModel get properly the device's density.

This can be done probably at main activity too,
but it's recommended centrally in an Application class as shown at Samples app.

--

Patrick Steiner

unread,
Mar 20, 2014, 3:48:33 AM3/20/14
to mapsfo...@googlegroups.com
Hi Victor,

thank you very much this also fixes my problem 😄

have a nice day.

 patrick
Reply all
Reply to author
Forward
Message has been deleted
0 new messages