title: Binary XML file line #7: Error inflating class TextView
body: <p>I am trying to run an already written code, which should be ok. Yet I get the error.</p>
  
  <p>I looked for similar problems but each problem and its solution are specific and don't give information that can be used for my problem.
  In other words, the exception message provided by Android Studio applies for endless possible problems.</p>
  
  <p>the xml file that causes the problem - activity_main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textAlignment="center"
          android:text="@string/contactsTtl"
          android:textSize="@dimen/TtlTxtSize"/&gt;
      &lt;ListView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:id="@+id/lvContacts"
          /&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>In the logcat I found that the exception is caused by</p>
  
  <pre><code>java.lang.UnsupportedOperationException: Can't convert value at index 2 to dimension: type=0x4
  </code></pre>
  
  <p>Here is the logcat of the exception:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.jsonreading, PID: 28802
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jsonreading/com.example.jsonreading.MainActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class TextView
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3003)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)
      at android.app.ActivityThread.-wrap14(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6816)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
   Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class TextView
   Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class TextView
   Caused by: java.lang.UnsupportedOperationException: Cant convert value at index 2 to dimension: type=0x4
      at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:737)
      at android.widget.TextView.&lt;init&gt;(TextView.java:1451)
      at android.widget.TextView.&lt;init&gt;(TextView.java:1038)
      at android.support.v7.widget.AppCompatTextView.&lt;init&gt;(AppCompatTextView.java:87)
      at android.support.v7.widget.AppCompatTextView.&lt;init&gt;(AppCompatTextView.java:83)
      at android.support.v7.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:177)
      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:102)
      at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
      at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
      at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
      at com.example.jsonreading.MainActivity.onCreate(MainActivity.java:43)
      at android.app.Activity.performCreate(Activity.java:6977)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)
      at android.app.ActivityThread.-wrap14(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:154)
      at android.app.ActivityThread.main(ActivityThread.java:6816)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)
  </code></pre>
  
  <p>The MainActivity.java file (not the whole file but just what's needed to run and get the exception):</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      Context context;
      List&lt;Contact&gt; contactList;
      ListView lvContacts;
      ContactsAdapter adapter;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  </code></pre>
  
  <p><strong>Edit</strong>
  The question of which my question was suggested to be a possible duplicate of regards a problem caused by not saving values in the dimens.xml file in the values folder. My issue was an invalid value: instead of writing only a number in the dimens file, my file also had the units</p>