Note that there are some explanatory texts on larger screens.

plurals
  1. POThere is no error shown and when any of the buttons in the activity are pressed, the app forces close?
    primarykey
    data
    text
    <p>Why are the buttons forcing the app to close, there are no errors that have been highlighted and as i am new to android development, i can't find the problem. Any help is appreciated thanks.</p> <p>This is the xml </p> <pre><code>&lt;LinearLayout android:layout_width="fill_parent" android:layout_height="447dp" android:background="@drawable/background" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Categories" &gt; &lt;Button android:id="@+id/author" android:layout_width="match_parent" android:layout_height="45dp" android:layout_alignParentEnd="true" android:layout_alignParentStart="true" android:background="@drawable/buttonpress" android:onClick="Author" android:text="@string/Author" android:textColor="#FA6900" android:textSize="21sp" /&gt; &lt;Button android:id="@+id/religion" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="22dp" android:background="@drawable/buttonpress" android:onClick="Religion" android:text="@string/Religion" android:textColor="#FA6900" android:textSize="21sp" /&gt; &lt;Button android:id="@+id/politician" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginTop="22dp" android:background="@drawable/buttonpress" android:onClick="Politician" android:text="@string/Politician" android:textColor="#FA6900" android:textSize="21sp" /&gt; &lt;Button android:id="@+id/happy" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginTop="23dp" android:background="@drawable/buttonpress" android:onClick="Happiness" android:text="@string/happy" android:textColor="#FA6900" android:textSize="21sp" /&gt; &lt;Button android:id="@+id/sport" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginTop="22dp" android:background="@drawable/buttonpress" android:onClick="Sport" android:text="@string/Sport" android:textColor="#FA6900" android:textSize="21sp" /&gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; </code></pre> <p>Java</p> <pre><code>package com.android.motivateme3; import android.os.Bundle; import android.os.Vibrator; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.support.v4.app.NavUtils; public class Categories extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_categories); // Show the Up button in the action bar. setupActionBar(); } /** * Set up the {@link android.app.ActionBar}. */ private void setupActionBar() { getActionBar().setDisplayHomeAsUpEnabled(true); } public void Sport(View v) { Intent intent = new Intent(getApplicationContext(), Sport.class); Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); startActivity(intent); } public void Religion(View v) { Intent intent = new Intent(getApplicationContext(), Religion.class); Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); startActivity(intent);} public void Author(View v) { Intent intent = new Intent(getApplicationContext(), Author.class); Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); startActivity(intent);} public void Politician(View v) { Intent intent = new Intent(getApplicationContext(), Politician.class); Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); startActivity(intent);} public void Happiness(View v) { Intent intent = new Intent(getApplicationContext(), Happiness.class); Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); startActivity(intent);} @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.categories, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } } </code></pre> <p>LogCat</p> <pre><code>05-04 16:08:41.014: D/memalloc(28579): /dev/pmem: Mapped buffer base:0x60519000 size:18690048 offset:14921728 fd:73 05-04 16:08:41.054: D/memalloc(28579): /dev/pmem: Mapped buffer base:0x61a6c000 size:35233792 offset:31465472 fd:79 05-04 16:08:41.064: D/OpenGLRenderer(28579): Flushing caches (mode 0) 05-04 16:08:41.074: D/memalloc(28579): /dev/pmem: Unmapping buffer base:0x5c63f000 size:31465472 offset:27697152 05-04 16:08:41.074: D/memalloc(28579): /dev/pmem: Unmapping buffer base:0x5ebfb000 size:10366976 offset:6598656 05-04 16:08:41.084: D/memalloc(28579): /dev/pmem: Unmapping buffer base:0x5f5de000 size:14921728 offset:11153408 05-04 16:08:41.824: D/memalloc(28579): /dev/pmem: Mapped buffer base:0x5c63f000 size:14921728 offset:11153408 fd:64 05-04 16:08:42.344: D/AndroidRuntime(28579): Shutting down VM 05-04 16:08:42.344: W/dalvikvm(28579): threadid=1: thread exiting with uncaught exception (group=0x40ac4210) 05-04 16:08:42.354: E/AndroidRuntime(28579): FATAL EXCEPTION: main 05-04 16:08:42.354: E/AndroidRuntime(28579): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.motivateme3/com.android.motivateme3.Author}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread.access$600(ActivityThread.java:127) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.os.Handler.dispatchMessage(Handler.java:99) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.os.Looper.loop(Looper.java:137) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread.main(ActivityThread.java:4441) 05-04 16:08:42.354: E/AndroidRuntime(28579): at java.lang.reflect.Method.invokeNative(Native Method) 05-04 16:08:42.354: E/AndroidRuntime(28579): at java.lang.reflect.Method.invoke(Method.java:511) 05-04 16:08:42.354: E/AndroidRuntime(28579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 05-04 16:08:42.354: E/AndroidRuntime(28579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 05-04 16:08:42.354: E/AndroidRuntime(28579): at dalvik.system.NativeStart.main(Native Method) 05-04 16:08:42.354: E/AndroidRuntime(28579): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.ImageButton 05-04 16:08:42.354: E/AndroidRuntime(28579): at com.android.motivateme3.Author.setupActionBar(Author.java:39) 05-04 16:08:42.354: E/AndroidRuntime(28579): at com.android.motivateme3.Author.onCreate(Author.java:28) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.Activity.performCreate(Activity.java:4465) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-04 16:08:42.354: E/AndroidRuntime(28579): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) 05-04 16:08:42.354: E/AndroidRuntime(28579): ... 11 more 05-04 16:08:49.964: I/Process(28579): Sending signal. PID: 28579 SIG: 9 05-04 16:11:35.094: D/memalloc(28746): /dev/pmem: Mapped buffer base:0x5f932000 size:10366976 offset:6598656 fd:70 </code></pre> <p>Manifest </p> <pre><code> &lt;uses-sdk android:minSdkVersion="11" android:targetSdkVersion="15" /&gt; &lt;uses-feature android:name="@string/hello_world" /&gt; &lt;uses-feature android:name="@string/Politician" /&gt; &lt;uses-feature android:name="@string/Sport" /&gt; &lt;uses-feature android:name="@string/Religion" /&gt; &lt;uses-feature android:name="@string/Author" /&gt; &lt;uses-feature android:name="@string/happy" /&gt; &lt;uses-feature android:name="@string/responseno" /&gt; &lt;uses-feature android:name="@string/responseyes" /&gt; &lt;uses-permission android:name="android.permission.VIBRATE" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.android.motivateme3.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.android.motivateme3.Sport" android:label="@string/title_activity_sport" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Religion" android:label="@string/title_activity_religion" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Author" android:label="@string/title_activity_author" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Politician" android:label="@string/title_activity_politician" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Sports" android:label="@string/title_activity_sports" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Happiness" android:label="@string/title_activity_happiness" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.Categories" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Feedback" android:label="@string/title_activity_feedback" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.MainActivity" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.SettingsActivity" android:label="@string/title_activity_settings" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.MainActivity" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Categories" android:label="@string/title_activity_categories" android:parentActivityName="com.android.motivateme3.MainActivity" &gt; &lt;meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.android.motivateme3.MainActivity" /&gt; &lt;/activity&gt; &lt;activity android:name="com.android.motivateme3.Favourites" android:label="@string/title_activity_favourites" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Author activity java package com.android.motivateme3;</p> <pre><code>import java.util.Random; import android.os.Bundle; import android.os.Vibrator; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.TextView; import android.support.v4.app.NavUtils; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; public class Author extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_author); // Show the Up button in the action bar. setupActionBar(); } /** * Set up the {@link android.app.ActionBar}, if the API is available. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupActionBar() { if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); ImageButton NextQuote = (ImageButton)findViewById(R.id.next); final TextView display = (TextView) findViewById(R.id.textView1); NextQuote.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); Random numGen = new Random(); int rNumber = numGen.nextInt(10); if (rNumber == 0) { display.setText(R.string.Author1); } else if (rNumber == 1) { display.setText(R.string.Author2); } else if (rNumber == 2) { display.setText(R.string.Author3); } else if (rNumber == 3) { display.setText(R.string.Author4); } else if (rNumber == 4) { display.setText(R.string.Author5); } else if (rNumber == 5) { display.setText(R.string.Author6); } else if (rNumber == 6) { display.setText(R.string.Author7); } else if (rNumber == 7) { display.setText(R.string.Author8); } else if (rNumber == 8) { display.setText(R.string.Author9); } else if (rNumber == 9) { display.setText(R.string.Author10); } } }); } ImageButton Sharing = (ImageButton)findViewById(R.id.share); Sharing.setOnClickListener(new View.OnClickListener() { public void onClick(View v){ Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(25); TextView text = (TextView)findViewById(R.id.textView1); String quote = text.getText().toString();{ Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("plain/text"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "This is a great quote (from the Motivate Me! app)"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, quote); startActivity(Intent.createChooser(shareIntent, "Share via:"));}};});} @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.author, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } } </code></pre> <p>XML author</p> <pre><code> &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Author" &gt; &lt;ImageButton android:id="@+id/next" android:layout_width="140dp" android:layout_height="50dp" android:layout_alignRight="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="14dp" android:background="@drawable/buttonpress" android:contentDescription="@string/Next" android:onClick="NextQuote" android:src="@drawable/navigationnextitem" /&gt; &lt;ImageButton android:id="@+id/share" android:layout_width="140dp" android:layout_height="50dp" android:layout_alignLeft="@+id/textView1" android:layout_alignTop="@+id/next" android:background="@drawable/buttonpress" android:contentDescription="@string/share" android:onClick="Sharing" android:src="@drawable/socialshare" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="300dp" android:layout_height="300dp" android:layout_centerHorizontal="true" android:layout_marginTop="14dp" android:background="@drawable/button_shape" android:text="@string/Getstarted" android:textColor="#FF6900" android:textSize="23sp" /&gt; &lt;/RelativeLayout&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