Note that there are some explanatory texts on larger screens.

plurals
  1. POChaging textview from another activity
    text
    copied!<p>I have two activities first one have two buttons second one have one textview</p> <p>what I need is when I click on the first button the second activity open and the textview show(hello) when I click on the second button the second activity open and the textview show(how are you)</p> <p>this is the first activity layout</p> <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/ScrollView1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:scrollbars="none" tools:context=".DailyPrayersActivity" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;Button android:id="@+id/btn1" style="@style/Button_Normal" android:background="@drawable/btn01" android:onClick="hello" android:text="@string/hello" /&gt; &lt;Button android:id="@+id/btn2" style="@style/Button_Normal" android:background="@drawable/btn01" android:onClick="hru" android:text="@string/hru" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>this is the java class of the first activity</p> <pre><code>package com.daily.morning; public class FirstActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_1); } public void hello(View v) { Intent i1 = new Intent(firstActivity.this, SecondActivity.class); SecondActivity.textview.setText("Hello"); startActivity(i1); finish(); } public void hru(View v) { Intent i2 = new Intent(FirstActivity.this, SecondActivity.class); SecondActivity.textview.setText("good morning"); startActivity(i2); finish(); } } </code></pre> <p>when I click on the first button or the second button the application force close</p> <p>this is the logcat</p> <pre><code>&gt;&gt;09-06 14:26:24.054: E/AndroidRuntime(30993): FATAL EXCEPTION: main 09-06 14:26:24.054: E/AndroidRuntime(30993): java.lang.IllegalStateException: Could not execute method of the activity 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$1.onClick(View.java:3699) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View.performClick(View.java:4223) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$PerformClick.run(View.java:17275) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Handler.handleCallback(Handler.java:615) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Handler.dispatchMessage(Handler.java:92) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.os.Looper.loop(Looper.java:137) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.app.ActivityThread.main(ActivityThread.java:4898) 09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invokeNative(Native Method) 09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invoke(Method.java:511) 09-06 14:26:24.054: E/AndroidRuntime(30993): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 09-06 14:26:24.054: E/AndroidRuntime(30993): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 09-06 14:26:24.054: E/AndroidRuntime(30993): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103) 09-06 14:26:24.054: E/AndroidRuntime(30993): at dalvik.system.NativeStart.main(Native Method) 09-06 14:26:24.054: E/AndroidRuntime(30993): Caused by: java.lang.reflect.InvocationTargetException 09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invokeNative(Native Method) 09-06 14:26:24.054: E/AndroidRuntime(30993): at java.lang.reflect.Method.invoke(Method.java:511) 09-06 14:26:24.054: E/AndroidRuntime(30993): at android.view.View$1.onClick(View.java:3694) 09-06 14:26:24.054: E/AndroidRuntime(30993): ... 12 more 09-06 14:26:24.054: E/AndroidRuntime(30993): Caused by: java.lang.NullPointerException 09-06 14:26:24.054: E/AndroidRuntime(30993): at com.daily.morning.FirstActivity.hello(FirstActivity.java:38) 09-06 14:26:24.054: E/AndroidRuntime(30993): ... 15 more </code></pre>
 

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