Note that there are some explanatory texts on larger screens.

plurals
  1. POResources$NotFoundException in Graphical Layout ADT preview (but app actually Works)
    primarykey
    data
    text
    <p>My problem is that loading an array of strings defined in XML works in the app but will result in an error in the ADT Graphical Layout preview.</p> <p>Now I can't see any graphics in the Graphical Layout because of this error, and it's difficult to work with other graphics. But the view is loading and displaying the strings fine if I build and run my app.</p> <p>So I suppose my code is correct but either:</p> <ul> <li>I am missing some limitations of the Graphical Layout preview and some workaround</li> <li>or perhaps I'm missing something obvious and doing things wrong even if it seems to work in the app </li> </ul> <p>I have a custom view where I get an array defined by me in an array.xml file.</p> <pre><code>public class ScoreTable extends View { [...] @Override protected void onDraw(Canvas canvas) { [...] int score_vals[] = getResources().getIntArray(R.array.score_vals); [...] } [...] } </code></pre> <p>My array is defined in res/values/array.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;array name="score_vals"&gt; &lt;item &gt;10&lt;/item&gt; &lt;item &gt;20&lt;/item&gt; &lt;item &gt;50&lt;/item&gt; &lt;/array&gt; &lt;/resources&gt; </code></pre> <p>Graphical Layout is blank and says:</p> <pre><code>Int array resource ID #0x7f050000 Exception details are logged in Window &gt; Show View &gt; Error Log </code></pre> <p>But of course I have "public static final int score_vals=0x7f050000;" in R.java!</p> <p>The details of this error are in a 50-deep stack, but resumes to this:</p> <pre><code>android.content.res.Resources$NotFoundException: Int array resource ID #0x7f050000 at android.content.res.Resources.getIntArray(Resources.java:405) at com.threecats.poker.ScoreTable.onDraw(ScoreTable.java:53) at android.view.View.draw(View.java:6740) [...] </code></pre> <p>So, should getResources().getXXXArray() work in the context of a ADT Graphical Layout preview?</p> <p>I would like to mention that I tried with both "array" and "array-integer" in the XML, and both work in the app but not in the preview. Also I tried to save the Context from the constructor of the view in a private Context member... didn't help either.</p>
    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