RuntimeException: Unable to start activity ComponentInfo{...}: android.view.InflateException

986 views Asked by At

when i start my app it crashes and logcat says:

12-03 16:52:12.486    8252-8252/de.kanalmeister.presentation E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.kanalmeister.presentation, PID: 8252
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.kanalmeister.presentation/de.kanalmeister.presentation.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
        at android.app.ActivityThread.access$700(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4998)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at android.widget.Toast.makeText(Toast.java:245)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:237)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActivity.createError(MainActivity.java:239)
        at de.kanalmeister.presentation.MainActivity.postData(MainActivity.java:231)
        at de.kanalmeister.presentation.MainActi

i already checked my layout file because it says "...InflateException: Binary XML file line #27..." but i didn't find a mistake.

Layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context=".MainActivity"
android:longClickable="false">

<!-- The primary full-screen view. This can be replaced with whatever view
     is needed to present your content, e.g. VideoView, SurfaceView,
     TextureView, etc. -->

<!-- This FrameLayout insets its children based on system windows using
     android:fitsSystemWindows. -->
<VideoView
    android:id="@+id/surface_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_gravity="center"
    android:textSize="40sp"
    android:textAlignment="center"
    android:gravity="center_vertical|center_horizontal"
    android:visibility="invisible" />

</FrameLayout>

code of my MainActivity:

package de.kanalmeister.presentation;

import ...

public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        String[] deviceID = {"***********", "***************"}; //IMEI von testgerät (**********: *************)
        int i = 0;
        boolean testgeraet = false;

        Calendar cal = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        Calendar cal3 = Calendar.getInstance();
        Calendar cal4 = Calendar.getInstance();
        Calendar cal5 = Calendar.getInstance();

        cal2.set(2014, Calendar.MAY, 8, 14, 0, 0);
        cal3.set(2014, Calendar.MAY, 8, 15, 35, 0);
        cal4.set(2014, Calendar.MAY, 15, 14, 0, 0);
        cal5.set(2014, Calendar.MAY, 15, 15, 35, 0);

        TelephonyManager tMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        setContentView(R.layout.activity_main); //layout-datei festlegen

        for (i = 0; i < deviceID.length; i++)
        {
            testgeraet = tMgr.getDeviceId().equals(deviceID[i]); //IMEI mit IMEI von zugelassenen testgeräten vergleichen
        }

        if (testgeraet)
        {
            start(true);
        }

        else
        {
            if (((cal3.getTimeInMillis() >= cal.getTimeInMillis()) && (cal.getTimeInMillis() >= cal2.getTimeInMillis()))
                    || ((cal5.getTimeInMillis() >= cal.getTimeInMillis()) && (cal.getTimeInMillis() >= cal4.getTimeInMillis()))) //aktuelles datum mit präsentationszeitraum vergleichen.
            {
                start(false);
            }

            else
            {
                if((cal5.getTimeInMillis() + 600000) < cal.getTimeInMillis()) //prüfen ab präsentation bereits vorbei
                {
                    TextView textView = (TextView) findViewById(R.id.textView);
                    textView.setVisibility(TextView.VISIBLE);
                    textView.setText("Die Präsentation ist vorbei. Die Urheberrechtlich geschützten Daten werden nun gelöscht. Die App ist danach unbrauchbar und sollte deinstalliert werden.");

                    try
                    {
                        sleep(5000);
                    }

                    catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }

                    if(delete("android.resource://" + getPackageName() + "/" + R.raw.trailer)) //wenn löschen erfolgreich
                    {
                        Intent intent = new Intent(Intent.ACTION_DELETE);
                        intent.setData(Uri.parse("package:" + this.getPackageName()));
                        startActivity(intent); //nutzer zum deinstallations-screen weiterleiten
                    }

                    else
                    {
                        createError(102);

                        textView.setText("Die Daten konnten nicht automatisch gelöscht werden. Deinstalliere die App bitte manuell. Wenn du die Daten aus der App kopierst, handelst du Rechtswidrig. Dies kann Straf- und Zivilrechtlich verfolgt werden.");

                        try
                        {
                            sleep(5000);
                        }

                        catch (InterruptedException e)
                        {
                            e.printStackTrace();
                        }

                        Intent intent = new Intent(Intent.ACTION_DELETE);
                        intent.setData(Uri.parse("package:" + this.getPackageName()));
                        startActivity(intent); //nutzer zum deinstallations-screen weiterleiten
                    }
                }

                else
                {
                    TextView textView = (TextView) findViewById(R.id.textView);
                    textView.setVisibility(TextView.VISIBLE);
                    textView.setText("Inhalt gesperrt! Bitte versuche es am 08.05.2014 oder 15.05.2014 zwischen 14:00-15:35 Uhr erneut.");

                    File file = new File("android.resource://" + getPackageName() + "/" + R.raw.trailer);

                    if (!file.setReadable(false)) //dateien vor zugriff schützen
                    {
                        createError(101);
                    }
                }
            }
        }
    }

    public void onPause()
    {
        //startService(new Intent(this, notifyService.class));
    }

    public boolean delete(String path) //datei löschen
    {
        File file = new File(path);
        return file.delete();
    }

    public void start(boolean tester)
    {
        File file = new File("android.resource://" + getPackageName() + "/" + R.raw.trailer);

        if (!file.setReadable(true)) //zugriff erlauben
        {
            createError(101);
        }

        final VideoView videoView = (VideoView) findViewById(R.id.surface_view);

        videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.trailer);

        videoView.start(); //video starten

        int score = 0;

        postData(getUserName(tester), score, false); //highscore senden

        //Intent i = new Intent(this, SettingsActivity.class);
        //startActivity(i);
    }

    public String getUserName(boolean tester)
    {
        AccountManager am = AccountManager.get(this); // "this" references the current Context
        Account[] accounts = new Account[0];

        if (am != null)
        {
            accounts = am.getAccountsByType("com.google");
        }

        if (tester)
        {
            return "TESTER_" + accounts[0].name;
        }
        else
        {
            return accounts[0].name;
        }
    }

    public void postData(String userName, int score, boolean error) //highscore senden
    {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost;
        String name1="username";
        String name2;

        if (error)
        {
            httppost = new HttpPost("http://testserver.info.cm/error_write.php");
            name2="errorcode";
        }

        else
        {
            httppost = new HttpPost("http://testserver.info.cm/highscore_write.php");
            name2="score";
        }

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair(name1, userName));
            nameValuePairs.add(new BasicNameValuePair(name2, String.valueOf(score)));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            createError(201);
        } catch (IOException e) {
            createError(202);
        }
    }

    public void createError(int errorcode)
    {
        Toast err = Toast.makeText(this, "Fehler " + String.valueOf(errorcode) + ". Die Daten werden automatisch an den Entwickler übermittelt.", Toast.LENGTH_SHORT);
        err.show();
        postData(getUserName(false), errorcode, true);
    }
}

and my androidmanifest:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <application
        android:allowBackup="false"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="de.kanalmeister.presentation.MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="de.kanalmeister.presentation.SettingsActivity"
            android:label="@string/title_activity_settings" >
        </activity>

        <service android:enabled="true" android:name=".notifyService" />
    </application>

</manifest>
1

There are 1 answers

10
Gopal Gopi On

I think you are getting error because of this line

  android:textAlignment="center"

which is used in TextView. I have copied your xml layout. and Eclipse showing me error saying there is no resource identifier for textAlignment in the package android.

remove android:textAlignment="center" attribute from TextView and try once...