Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my Android App crashing when I'm trying to access string resources?
    primarykey
    data
    text
    <p>I'm doing the HelloLinearLayout tutorial, but using string resources instead of hard coding the strings directly into the XML like the tutorial. When I run the app using string resources, it crashes immediately. When I hard code the strings into the XML code, everything works fine. Any ideas as to why my app is crashing? Thanks</p> <p><strong>Main.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"&gt; &lt;TextView android:text="@string/box1text" android:gravity="center_horizontal" android:background="@string/box1color" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="@string/box1weight" /&gt; &lt;TextView android:text="@string/box2text" android:gravity="center_horizontal" android:background="@string/box2color" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="@string/box2weight" /&gt; &lt;TextView android:text="@string/box3text" android:gravity="center_horizontal" android:background="@string/box3color" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="@string/box2weight" /&gt; &lt;TextView android:text="@string/box4text" android:gravity="center_horizontal" android:background="@string/box4color" android:layout_height="fill_parent" android:layout_width="wrap_content" android:layout_weight="@string/box4weight" /&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p><strong>strings.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="hello"&gt;Hello World, HelloLinearLayoutActivity!&lt;/string&gt; &lt;string name="app_name"&gt;HelloLinearLayout&lt;/string&gt; &lt;string name="box1text"&gt;red&lt;/string&gt; &lt;string name="box1color"&gt;#aa0000&lt;/string&gt; &lt;string name="box1weight"&gt;1&lt;/string&gt; &lt;string name="box2text"&gt;green&lt;/string&gt; &lt;string name="box2color"&gt;#00aa00&lt;/string&gt; &lt;string name="box2weight"&gt;1&lt;/string&gt; &lt;string name="box3text"&gt;blue&lt;/string&gt; &lt;string name="box3color"&gt;#0000aa&lt;/string&gt; &lt;string name="box3weight"&gt;1&lt;/string&gt; &lt;string name="box4text"&gt;yellow&lt;/string&gt; &lt;string name="box4color"&gt;#aaaa00&lt;/string&gt; &lt;string name="box4weight"&gt;1&lt;/string&gt; &lt;/resources&gt; </code></pre> <p><strong>hellolinearlayoutactivity.java</strong></p> <pre><code>package com.example.hellolinearlayout; import android.app.Activity; import android.os.Bundle; public class HelloLinearLayoutActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload