0

I just put together a new Android project in Eclipse, and so far I only have one package with one activity (the auto-generated code from Eclipse), and all I did was add two buttons to the main.xml layout file.

When I try to debug the app, the emulator crashes and I get the error "Binary XML file line #31: Error inflating class android.widget.FrameLayout."

I'm not even using FrameLayout!

Here is the layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#99CCFF">

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New" />

<Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save" />

</LinearLayout>

And here is the main Activity file (again, this is just the default code that Eclipse generates when you create a new project):

package com.myapp.main;

import android.app.Activity;
import android.os.Bundle;

public class MyApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
}

And just for the heck of it, here's the manifest file as well:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.main"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name="com.myapp.main.MyApp"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

So far as I can see, this is 99% auto-generated code, and I can see no reason why I would be getting an InflateException on "FrameLayout" when I'm not even using a FrameLayout.

So very confused ...

Here is what I get in LogCat:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.main/com.myapp.main.MyApp}: android.view.InflateException: Binary XML file line #31: Error inflating class android.widget.FrameLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class android.widget.FrameLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:596)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2456)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2516)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:220)
at android.app.Activity.setContentView(Activity.java:1777)
at com.myapp.main.MyApp.onCreate(MyApp.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
JMax2012
  • 373
  • 2
  • 6
  • 24

1 Answers1

0

I'm having trouble seeing what's wrong with your code as well. Could you copy and paste the entire stack trace you get when your app crashes? I think it might give us more of an insight as to what is going on.

You can either get the stack trace from Logcat in Eclipse, or you can open a terminal and type "adb logcat"

Nick King
  • 47
  • 10
  • Yes, I'll update the question. I didn't see anything too helpful in the logcat, though. – JMax2012 Jul 06 '12 at 15:06
  • What is the argument in your setContentView() method call in onCreate? – Nick King Jul 06 '12 at 15:14
  • The argument ("R.layout.main") is the main.xml layout file, I believe (the main.xml code is included in the question above). – JMax2012 Jul 06 '12 at 15:19
  • I duplicated your project to the best of my ability and I wasn't able to reproduce the error. The strangest thing is that your error from Logcat is pointing to a line number that isn't even in your main.xml file (which is only 20 lines long). Maybe you could try cleaning your project in Eclipse? You can do that by going to the Project menu at the top and clicking "Clean..." – Nick King Jul 06 '12 at 15:28