Note that there are some explanatory texts on larger screens.

plurals
  1. POStart another activity by clicking a button
    primarykey
    data
    text
    <p>So heres my problem. I set up a button that when clicked should open a new activity but when it is clicked I receive an error: Unfortunately "app_name" has stopped working my logcat says :Fatal Exception Main</p> <p>So heres my xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="30dp" android:layout_marginTop="58dp" android:text="Monday" android:textSize="20sp"/&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Tuesday" /&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_below="@+id/textView2" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Wednesday" /&gt; &lt;TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView3" android:layout_below="@+id/textView3" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Thursday" /&gt; &lt;TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView4" android:layout_below="@+id/textView4" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Friday" /&gt; &lt;TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView5" android:layout_below="@+id/textView5" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Saturday" /&gt; &lt;TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView6" android:layout_below="@+id/textView6" android:layout_marginTop="30dp" android:textSize="20sp" android:text="Sunday" /&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_alignParentRight="true" android:layout_marginRight="46dp" android:text="Edit" android:onClick="mondayintent" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView2" android:layout_alignBottom="@+id/textView2" android:layout_alignLeft="@+id/button1" android:text="Edit" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView3" android:layout_alignBottom="@+id/textView3" android:layout_alignLeft="@+id/button2" android:text="Edit" /&gt; &lt;Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView4" android:layout_alignBottom="@+id/textView4" android:layout_alignLeft="@+id/button3" android:text="Edit" /&gt; &lt;Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView5" android:layout_alignBottom="@+id/textView5" android:layout_alignLeft="@+id/button4" android:text="Edit" /&gt; &lt;Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView6" android:layout_alignBottom="@+id/textView6" android:layout_alignLeft="@+id/button5" android:text="Edit" /&gt; &lt;Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView7" android:layout_alignBottom="@+id/textView7" android:layout_alignLeft="@+id/button6" android:text="Edit" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and the second Xml to which im trying to reach in another activity:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:textSize="40sp" android:text="Monday" /&gt; &lt;EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_marginTop="36dp" android:layout_toLeftOf="@+id/textView1" android:ems="3" android:inputType="time" /&gt; &lt;EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText1" android:layout_alignBottom="@+id/editText1" android:layout_centerHorizontal="true" android:ems="3" android:inputType="time" &gt; &lt;requestFocus /&gt; &lt;/EditText&gt; &lt;Spinner android:id="@+id/profileSelector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/editText2" android:layout_toRightOf="@+id/textView1" android:ems="3" android:prompt="@string/profile" android:entries="@array/profileSelector"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Finally the code that supports both:</p> <pre><code>package com.example.hush; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.widget.Button; import android.view.View.OnClickListener; public class MainActivity extends Activity { Intent clickedDay; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainlayout); Button mondayEdit=(Button)findViewById(R.id.button1); } public void mondayintent() { clickedDay= new Intent(this,Monday.class); startActivity(clickedDay); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>second activity code:</p> <pre><code>package com.example.hush; import android.app.Activity; import android.os.Bundle; import android.widget.Button; public class Monday extends Activity{ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.monday); } } </code></pre> <p>Below I have added my android-manifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hush" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.hush.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.hush.Monday" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="com.example.hush.Monday" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    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