Note that there are some explanatory texts on larger screens.

plurals
  1. POsetText will crush the app
    primarykey
    data
    text
    <p>Hi I am starting my first android app and trying to get the TextView changed the words after some time.</p> <pre><code>public class Game1Activity extends Activity { GameViews ngv; private static String gameId = "game1Activity-game"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.game1_layout); ngv = (GameViews)findViewById(R.id.Game1); ngv.setTextView((TextView)findViewById(R.id.Text)); }; } public class GameViews extends View { private TextView gameText; private long time1 = System.currentTimeMillis(); public GameViews(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initGameViews(); } public GameViews(Context context, AttributeSet attrs) { super(context, attrs); initGameViews(); } public void setTextView(TextView tv) { gameText = tv; } public void initGameViews() { setFocusable(true); Resources r = this.getContext().getResources(); changeGameText(); } public void changeGameText() { while (true) { if (System.currentTimeMillis() - time1 &gt; 100) { gameText.setText(R.string.hi2); return; } } } } </code></pre> <p>the layout XML file is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;game1.code.GameViews android:id="@+id/Game1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" tileSize="24" /&gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_vertical" android:gravity="center" &gt; &lt;TextView android:id="@+id/Text" android:text="@string/hi1" android:visibility="visible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center_horizontal" android:textColor="#ff8888ff" android:textSize="24sp"/&gt; &lt;/RelativeLayout&gt; &lt;/FrameLayout&gt; </code></pre> <p>and the strings.xml is:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="hi1"&gt;hi1&lt;/string&gt; &lt;string name="hi2"&gt;hi2&lt;/string&gt; &lt;/resources&gt; </code></pre> <p>When I try to run, the logCat tells me that:</p> <pre><code>03-08 03:19:28.067: E/AndroidRuntime(602): Caused by: java.lang.NullPointerException 03-08 03:19:28.067: E/AndroidRuntime(602): game1.code.GameViews.changeGameText(GameViews.java:67) 03-08 03:19:28.067: E/AndroidRuntime(602): game1.code.GameViews.initGameViews(GameViews.java:52) </code></pre> <p>It seems that the setText is causing the issue, as when I commented out this line there is no problem occurring.</p> <p>Did I miss anything? </p>
    singulars
    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.
    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