Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid eclipse Switch Case not working
    primarykey
    data
    text
    <p>I have an app that alot of users have helped me on so far and I really appreciate it. Now I have a force close issue when the case is exicuted below. When I click the button 2 it will load the Ship.Class and everything works like I want it too. When I click button1 It will not load Ocean.Class and it force closes. The Ocean.Class is a mirror of the Ship.Class except for the variable names have been updated to reflect the different class. Is using the variable (a) like I am in the switch not something that is allowable? </p> <pre><code>package com.androidsleepmachine.gamble; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; public class Ocean extends Activity implements View.OnClickListener { public static final Integer[] TIME_IN_MINUTES = { 30, 45, 60, 180, 360 }; public MediaPlayer mediaPlayer; public Handler handler = new Handler(); public Button button1; public Spinner spinner1; // Initialize the activity @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocean); button1 = (Button) findViewById(R.id.btn1); button1.setOnClickListener(this); spinner1 = (Spinner) findViewById(R.id.spinner1); ArrayAdapter&lt;Integer&gt; adapter = new ArrayAdapter&lt;Integer&gt;(this, android.R.layout.simple_spinner_item, TIME_IN_MINUTES); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner1.setAdapter(adapter); } // Play the sound and start the timer private void playSound(int resourceId) { // Cleanup any previous sound files cleanup(); // Create a new media player instance and start it mediaPlayer = MediaPlayer.create(this, resourceId); mediaPlayer.start(); // Create the timer to stop the sound after x number of milliseconds int selectedTime = TIME_IN_MINUTES[spinner1.getSelectedItemPosition()]; handler.postDelayed(runnable, selectedTime * 60 * 1000); } // Handle button callback @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn1: playSound(R.raw.ocean_birds); break; } } // Stop the sound and cleanup the media player public void cleanup() { if (mediaPlayer != null) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } // Cancel any previously running tasks handler.removeCallbacks(runnable); } // Runnable task used by the handler to stop the sound public Runnable runnable = new Runnable() { public void run() { cleanup(); } }; } </code></pre> <p>This is what I gathered from the Logcat</p> <pre><code>09-17 11:11:15.704: I/dalvikvm(1634): | sysTid=1634 nice=0 sched=0/0 cgrp=[fopen- error:2] handle=-1207757760 09-17 11:11:58.690: E/Trace(1665): error opening trace file: No such file or directory (2) 09-17 11:18:47.446: I/dalvikvm(1735): | sysTid=1735 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1207757760 09-17 11:39:46.139: E/Trace(1758): error opening trace file: No such file or directory (2) 09-17 11:39:53.705: I/dalvikvm(1758): | sysTid=1758 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1207757760 09-17 11:40:00.356: E/Trace(1774): error opening trace file: No such file or directory (2) &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidsleepmachine.gamble" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="16" android:targetSdkVersion="18" /&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.androidsleepmachine.gamble.Home" 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.androidsleepmachine.gamble.Ship" /&gt; &lt;activity android:name="com.androidsleepmachine.gamble.Ocean" /&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.
 

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