I know this has been asked a lot on SO, but unfortunately none of the answers did solve my problem.
I have 3 Android devices for testing + emulator and my app just works fine on all of them, but when I publish the app I get this error (only on few devices, not all):
java.lang.RuntimeException: Unable to start activity ComponentInfo{<package>/<package>.<ProjectName>Activity}: android.view.InflateException: Binary XML file line #10: Error inflating class <package>.MainSurfaceView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access2300ドル(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <package>.MainSurfaceView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
at android.app.Activity.setContentView(Activity.java:1647)
at <package>.<ProjectName>Activity.onCreate(Unknown Source)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
... 11 more
Caused by: java.lang.ClassNotFoundException: <package>.MainSurfaceView in loader dalvik.system.PathClassLoader[/data/app/<package>-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.view.LayoutInflater.createView(LayoutInflater.java:466)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
The class extends class GLSurfaceView and has 3 constructors (GLSurfaceView supports only 2, but I read on SO that the missing third may cause the problem - it doesn't).
Class (only constructors):
public class MainSurfaceView extends GLSurfaceView {
public MainSurfaceView(Context context) {
super(context);
}
public MainSurfaceView(Context context, AttributeSet attrs){
super(context, attrs);
}
public MainSurfaceView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs);
}
}
Adding constructor
public MainSurfaceView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs);
}
did not solve the problem.
My manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<package>"
android:versionCode="5"
android:versionName="1.2.1">
<uses-sdk android:minSdkVersion="8" />
<supports-screens android:largeScreens="true"
android:anyDensity="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".<project>Activity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="keyboard|keyboardHidden|orientation" />
</application>
</manifest>
And my layout file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
android:layout_width="480dp"
android:layout_height="800dp"
android:layout_gravity="center">
<<package>.MainSurfaceView android:id="@+id/glSurface" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_gravity="top|left"/>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="visible"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="<id>"
ads:loadAdOnCreate="true"/>
</FrameLayout>
Thanks for any help. It would be also very helpful if someone can tell me how to recreate the error.
-
It happend to my published apps too, even with an Activity class.I think that some phones just have bugs or have to be rebooted.VinceFR– VinceFR2012年06月09日 17:37:28 +00:00Commented Jun 9, 2012 at 17:37
-
K-ballo: Yes, I use ProGuard; VinceFR: The problem also occures on Android 2.3.5 (I don't know if it's an official release), but the amazon team refuses to publish my app just beacause it doesn't work on 2.3.5cleanac– cleanac2012年06月09日 19:23:07 +00:00Commented Jun 9, 2012 at 19:23
-
2@cleanac: If you have updated to ADTv17 or above, the old ProGuard files will do this to you. Create a new empty project, and see project.properties and proguard-properties and modify your current project accordingly.K-ballo– K-ballo2012年06月09日 19:24:28 +00:00Commented Jun 9, 2012 at 19:24
-
@K-ballo: With your help I could finally recreate the error and fix it. Thank you. I think it would be nice if you write an answer so I can accept it as the sollution.cleanac– cleanac2012年06月10日 16:08:38 +00:00Commented Jun 10, 2012 at 16:08
2 Answers 2
If you have updated to ADTv17 or above, the old ProGuard files will do this to you. Create a new empty project, and see project.properties and proguard-properties and modify your current project accordingly.
Comments
I suggest to use try catch block for finding the exact error. On my case, I also found "java.lang.ClassNotFoundException". After I debug it, it is caught on in catch block. It show "android.view.InflateException: Binary XML file line #7: Error inflating class fragment". Thus, when we get error as above, we need to debug it first to find the exact error.
Comments
Explore related questions
See similar questions with these tags.