Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As your <code>TextView</code> is in another <code>SecondActivity</code>.Firts You need to fetch it via XML through <code>setContentView()</code> and <code>findViewById()</code>, but as <code>FirstActivity</code> has already it's own <code>XML Layout</code>. Fetching <code>View</code> is totally wrong turn.</p> <p>You need to achieve your goal by pass value in a <code>Bundle</code> from <code>FirstActivity</code> to <code>SecondActivity</code> with some <code>Key</code> and fetch it there.</p> <p>Here is a snipped how you can achieve these: -</p> <pre><code> public void hello(View v) { Intent i1 = new Intent(firstActivity.this, SecondActivity.class); i.putExtra("KEY",YourData); // i.putExtra("greetings", "Hello"); --&gt; Hello is data and greeting is key to fetch from. startActivity(i1); finish(); } </code></pre> <p>In SecondActivity class</p> <p>You need fetch your <code>Bundle</code> which you sent from <code>FirstActivity</code> to <code>SecondActivity</code> and fetch <code>value</code> against the same <code>KEY</code> which you passed on from your <code>FirstActivity</code>.</p> <pre><code>Bundle extras = getIntent().getExtras(); if(extras !=null) { String value = extras.getString("KEY"); // String value = extras.getString("greetings"); --&gt; which will fetch data from key greetings to value. Thus value now contains Hello. TextView.setText(value); } </code></pre> <p>Note: Exception Thrown in your Case as you trying to call method <code>setText()</code> on <code>TextView</code> which is not even present in <code>FirstActivity</code>. That's the reason why RunTime throws <code>IllegalStateException</code></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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