5 Replies - 2306 Views - Last Post: 12 December 2013 - 07:54 PM

#1 vpdic   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 24-November 13

Crash occuring when trying to load a SeekBar

Posted 11 December 2013 - 07:53 PM

I'm very new to Android development, and Java as well so I suspect I'm missing something obvious. After thorough testing and researching I have not been able to determine what exactly is causing my crash. It's happening after I create my SeekBar(sk), and I really can't figure out why.

The progress is that when a button is pressed text is displayed on a new window(works), then an audio clip plays in a loop(works). This new window has the added benefit of controlling the volume with a seekbar, which is where I'm having a problem. I want the volume to update on (mp) when the seekbar position is changed. I know that using anything outside of 0-1 for a volume will crash the project but that's something I will get to later.

Any help is appreciated, thank you.
public class PopText extends Activity {

	@SuppressLint("NewApi")
	public int resID;// = getResources().getIdentifier("test", "raw",  getPackageName());
	public MediaPlayer mp;// = MediaPlayer.create(PopText.this, resID);


	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);

	    // Get the message from the intent
	    Intent intent = getIntent();
	    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

	    // Create the text view
	    TextView textView = new TextView(this);
	    textView.setTextSize(40);
	    textView.setText(message);

	    // Set the text view as the activity layout
	    setContentView(textView);
	    
	    resID = getResources().getIdentifier("choose", "raw",  getPackageName());
	    mp = MediaPlayer.create(PopText.this, resID);
	   // mp.setWakeMode(context, mode);
	    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
	    mp.setLooping(true);
	    mp.start();

// CRASH OCCURS SOMEWHERE IN HERE
	    final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);     
	    sk.setonseekBarChangeListener(new onseekBarChangeListener() {       

	    @Override       
	    public void onstopTrackingTouch(SeekBar seekBar) {      
	        // TODO Auto-generated method stub      
	    }       

	    @Override       
	    public void onstartTrackingTouch(SeekBar seekBar) {     
	        // TODO Auto-generated method stub      
	    }       

	    @Override       
	    public void onprogressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
	        // TODO Auto-generated method stub      
			//try {
	    	// mp.setVolume(progress, progress);
			//}
			//finally {
				
			//}
	    }       
	    });         
	 
	}
// END CRASHING SEGMENT
//... A FEW MORE closing brackets and unrelated routines below ...




Is This A Good Question/Topic? 0
  • +

Replies To: Crash occuring when trying to load a SeekBar

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: Crash occuring when trying to load a SeekBar

Posted 11 December 2013 - 08:51 PM

Check the LogCat for the error message. We can't help you without it.

Here, don't ignore your Exception. Include a catch() block and log your Exception.
 public void onprogressChanged(SeekBar seekBar, int progress,boolean fromUser) {    
48	            // TODO Auto-generated method stub     
49	            //try {
50	            // mp.setVolume(progress, progress);
51	            //}
52	            //finally {
53	                


Was This Post Helpful? 0
  • +
  • -

#3 vpdic   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 24-November 13

Re: Crash occuring when trying to load a SeekBar

Posted 12 December 2013 - 01:22 PM

the Try Catch that is commented out is not the source of the problem. It's just something I have to work with that I haven't yet completed to an operational level.

Here is the logcat though,
12-12 15:20:46.723: I/dalvikvm(271): Could not find method com.outertouch.sleepguide2.PopText.getActionBar, referenced from method com.outertouch.sleepguide2.PopText.setupActionBar
12-12 15:20:46.723: W/dalvikvm(271): VFY: unable to resolve virtual method 5068: Lcom/outertouch/sleepguide2/PopText;.getActionBar ()Landroid/app/ActionBar;
12-12 15:20:46.723: D/dalvikvm(271): VFY: replacing opcode 0x6e at 0x0006
12-12 15:20:46.723: D/dalvikvm(271): VFY: dead code 0x0009-000d in Lcom/outertouch/sleepguide2/PopText;.setupActionBar ()V
12-12 15:20:47.043: D/AndroidRuntime(271): Shutting down VM
12-12 15:20:47.043: W/dalvikvm(271): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-12 15:20:47.063: E/AndroidRuntime(271): FATAL EXCEPTION: main
12-12 15:20:47.063: E/AndroidRuntime(271): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.outertouch.sleepguide2/com.outertouch.sleepguide2.PopText}: java.lang.NullPointerException
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.os.Handler.dispatchMessage(Handler.java:99)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.os.Looper.loop(Looper.java:123)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at java.lang.reflect.Method.invokeNative(Native Method)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at java.lang.reflect.Method.invoke(Method.java:521)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at dalvik.system.NativeStart.main(Native Method)
12-12 15:20:47.063: E/AndroidRuntime(271): Caused by: java.lang.NullPointerException
12-12 15:20:47.063: E/AndroidRuntime(271): 	at com.outertouch.sleepguide2.PopText.onCreate(PopText.java:57)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-12 15:20:47.063: E/AndroidRuntime(271): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-12 15:20:47.063: E/AndroidRuntime(271): 	... 11 more



Was This Post Helpful? 0
  • +
  • -

#4 Apokio   User is offline

  • D.I.C Addict

Reputation: 135
  • View blog
  • Posts: 511
  • Joined: 14-August 09

Re: Crash occuring when trying to load a SeekBar

Posted 12 December 2013 - 02:18 PM

What does your xml look like for the seekbar? The NullPointerException is showing on line 57 but in the code you posted line 57 is blank. Is that the case in your IDE.
Was This Post Helpful? 0
  • +
  • -

#5 vpdic   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 24-November 13

Re: Crash occuring when trying to load a SeekBar

Posted 12 December 2013 - 07:25 PM

That would be the sk. onseekbarchangelistener line. Maybe it's not initialized properly, not sure how to resolve if that is the case.
Was This Post Helpful? 0
  • +
  • -

#6 vpdic   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 84
  • Joined: 24-November 13

Re: Crash occuring when trying to load a SeekBar

Posted 12 December 2013 - 07:54 PM

Here is the XML for the PopText.java
<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PopText" >

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:max="100"
        android:layout_marginTop="100dp" />

</RelativeLayout>



The seekbar is already placed on the window.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1