Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do Changes to Edit text field which is in the main activity, from the activity loaded inside the tab host which is in the main activity?
    primarykey
    data
    text
    <p>I am developing an app, where in my main activity, there is a tab host and a edit text field. Tab host will load different activities inside each tab when changing tabs. In each activity that loads in each tab I have placed a button. When I click the button I need some text to be displayed in the Edit text in the main activity.But I am getting "app forced closed" whenever i try to initialize the edit text field in the other activities than the main activity.</p> <p>So if anybody can help me get the edit text get value from the press from the button in the activity loaded in the tab it would be a great help</p> <p>This is the screen shot blue box will be the activity that loads in every tab, out of it will be the main activity</p> <p><img src="https://i.stack.imgur.com/UHz4A.jpg" alt="Screen shot of my app"></p> <p>This is what Logcat out put looks like when the force close occurs. </p> <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.batz.voiceforyou/com.batz.voiceforyou.Things}: java.lang.NullPointerException 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2065) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1906) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:694) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.widget.TabHost.setCurrentTab(TabHost.java:358) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:150) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:553) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.view.View.performClick(View.java:4129) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.view.View$PerformClick.run(View.java:17143) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.os.Handler.handleCallback(Handler.java:615) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.os.Handler.dispatchMessage(Handler.java:92) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.os.Looper.loop(Looper.java:137) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.ActivityThread.main(ActivityThread.java:4802) 03-24 17:55:23.928: E/AndroidRuntime(23581): at java.lang.reflect.Method.invokeNative(Native Method) 03-24 17:55:23.928: E/AndroidRuntime(23581): at java.lang.reflect.Method.invoke(Method.java:511) 03-24 17:55:23.928: E/AndroidRuntime(23581): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813) 03-24 17:55:23.928: E/AndroidRuntime(23581): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580) 03-24 17:55:23.928: E/AndroidRuntime(23581): at dalvik.system.NativeStart.main(Native Method) 03-24 17:55:23.928: E/AndroidRuntime(23581): Caused by: java.lang.NullPointerException 03-24 17:55:23.928: E/AndroidRuntime(23581): at com.batz.voiceforyou.Things.onCreate(Things.java:19) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.Activity.performCreate(Activity.java:5013) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 03-24 17:55:23.928: E/AndroidRuntime(23581): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2029) 03-24 17:55:23.928: E/AndroidRuntime(23581): ... 18 more </code></pre> <p>Here is the MainActivity Code</p> <pre><code>public class MainActivity extends TabActivity { String text=""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText mainText=(EditText) findViewById(R.id.maintext); Resources res = getResources(); TabHost tabs = getTabHost(); Intent regular = new Intent(this, Regular.class); TabSpec reg = tabs.newTabSpec("Regular") .setIndicator("", res.getDrawable(R.drawable.ic_launcher)) .setContent(regular); Intent things = new Intent(this, Things.class); TabSpec thngs = tabs.newTabSpec("Things") .setIndicator("", res.getDrawable(R.drawable.ic_launcher)) .setContent(things); tabs.addTab(reg); tabs.addTab(thngs); tabs.setCurrentTab(0); } } </code></pre> <p>This is one of the activity that loads inside the tab</p> <pre><code>public class Regular extends Activity { String text=""; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.regular); //final EditText mainText=(EditText) findViewById(R.id.maintext); //text=mainText.getText().toString(); Button regbtn = (Button) findViewById(R.id.regularbutton); regbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { text=text+" regular"; //mainText.setText(text); } }); } </code></pre> <p>}</p> <p>Here you can see the 3 line which I have commented, If I remove those lines the app will force close when starting. If you want I can share the layouts too</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.
 

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