My Application starts - crashes (No Errors)

Put your problem here if it does not fit any of the other categories.

My Application starts - crashes (No Errors)

Postby JediMind91 » Wed Feb 15, 2012 11:35 pm

Hey

I'm programming with java again, the programm worked yesterday but now it crashes.
I changed some things in the Layout in then this line got an error:
textState = (TextView)findViewById(R.id.state);
With gridline it worked but i changed it back.
In the Main XML the part is:
<GridLayout
android:id="@+id/state"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</GridLayout>


Full Code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package my.mameli.space;
  2.  
  3. import android.app.Activity;
  4. import android.media.MediaPlayer;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9.  
  10. public class Mamely extends Activity {
  11.        
  12.         MediaPlayer mediaPlayer;
  13.         Button buttonPlayPause, buttonQuit;
  14.         TextView textState;
  15.        
  16.        
  17.         private int stateMediaPlayer;
  18.         private final int stateMP_NotStarter = 0;
  19.         private final int stateMP_Playing = 1;
  20.         private final int stateMP_Pausing = 2;
  21.        
  22.     /** Called when the activity is first created. */
  23.     @Override
  24.     public void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.main);
  27.        
  28.         buttonPlayPause = (Button)findViewById(R.id.playpause);
  29.         buttonQuit = (Button)findViewById(R.id.quit);
  30.         textState = (TextView)findViewById(R.id.state);
  31.        
  32.         buttonPlayPause.setOnClickListener(buttonPlayPauseOnClickListener);
  33.         buttonQuit.setOnClickListener(buttonQuitOnClickListener);
  34.        
  35.         initMediaPlayer();
  36.        
  37.     }
  38.    
  39.     private void initMediaPlayer()
  40.     {
  41.         mediaPlayer = new  MediaPlayer();
  42.         mediaPlayer = MediaPlayer.create(Mamely.this, R.raw.music);
  43.         stateMediaPlayer = stateMP_NotStarter;
  44.         textState.setText("- Stopped -");
  45.     }
  46.    
  47.     Button.OnClickListener buttonPlayPauseOnClickListener
  48.         = new Button.OnClickListener(){
  49.  
  50.                         public void onClick(View v) {
  51.                                 // TODO Auto-generated method stub
  52.                                 switch(stateMediaPlayer){
  53.                                 case stateMP_NotStarter:
  54.                                         mediaPlayer.start();
  55.                                         buttonPlayPause.setText("Pause");
  56.                                         textState.setText("- PLAYING -");
  57.                                         stateMediaPlayer = stateMP_Playing;
  58.                                         break;
  59.                                 case stateMP_Playing:
  60.                                         mediaPlayer.pause();
  61.                                         buttonPlayPause.setText("Play");
  62.                                         textState.setText("- PAUSING -");
  63.                                         stateMediaPlayer = stateMP_Pausing;
  64.                                         break;
  65.                                 case stateMP_Pausing:
  66.                                         mediaPlayer.start();
  67.                                         buttonPlayPause.setText("Pause");
  68.                                         textState.setText("- PLAYING -");
  69.                                         stateMediaPlayer = stateMP_Playing;
  70.                                         break;
  71.                                 }
  72.                                
  73.                         }
  74.     };
  75.    
  76.     Button.OnClickListener buttonQuitOnClickListener
  77.         = new Button.OnClickListener(){
  78.  
  79.                 public void onClick(View v) {
  80.                         // TODO Auto-generated method stub
  81.                         mediaPlayer.stop();
  82.                         mediaPlayer.release();
  83.                         finish();
  84.                 }      
  85.     };
  86. }
  87.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:orientation="vertical" >
  6.  
  7.     <GridLayout
  8.        android:id="@+id/gridLayout2"
  9.        android:layout_width="match_parent"
  10.        android:layout_height="wrap_content" >
  11.     </GridLayout>
  12.  
  13.     <TextView
  14.        android:layout_width="fill_parent"
  15.        android:layout_height="wrap_content"
  16.        android:text="Developed by Crossdev" />
  17.  
  18.     <Button
  19.        android:id="@+id/playpause"
  20.        android:layout_width="fill_parent"
  21.        android:layout_height="wrap_content"
  22.        android:text="Play" />
  23.  
  24.     <TabHost
  25.        android:id="@android:id/tabhost"
  26.        android:layout_width="match_parent"
  27.        android:layout_height="151dp"
  28.        android:layout_weight="0.19" >
  29.  
  30.  
  31.         <LinearLayout
  32.            android:id="@+id/linearLayout1"
  33.            android:layout_width="match_parent"
  34.            android:layout_height="match_parent"
  35.            android:orientation="vertical" >
  36.  
  37.             <FrameLayout
  38.                android:id="@android:id/tabcontent"
  39.                android:layout_width="match_parent"
  40.                android:layout_height="4dp" >
  41.  
  42.                 <LinearLayout
  43.                    android:id="@+id/Text"
  44.                    android:layout_width="match_parent"
  45.                    android:layout_height="14dp" >
  46.                 </LinearLayout>
  47.  
  48.                 <LinearLayout
  49.                    android:id="@+id/Info"
  50.                    android:layout_width="match_parent"
  51.                    android:layout_height="match_parent" >
  52.                 </LinearLayout>
  53.  
  54.                 <LinearLayout
  55.                    android:id="@+id/Support"
  56.                    android:layout_width="match_parent"
  57.                    android:layout_height="match_parent" >
  58.                 </LinearLayout>
  59.  
  60.                 <TabWidget
  61.                    android:id="@android:id/tabs"
  62.                    android:layout_width="match_parent"
  63.                    android:layout_height="44dp" >
  64.                 </TabWidget>
  65.  
  66.                 <GridLayout
  67.                    android:id="@+id/gridLayout3"
  68.                    android:layout_width="match_parent"
  69.                    android:layout_height="match_parent" >
  70.                 </GridLayout>
  71.  
  72.                 <ImageView
  73.                    android:id="@+id/imageView1"
  74.                    android:layout_width="wrap_content"
  75.                    android:layout_height="wrap_content"
  76.                    android:src="@drawable/ic_flag" />
  77.             </FrameLayout>
  78.  
  79.         </LinearLayout>
  80.  
  81.     </TabHost>
  82.  
  83.     <Button
  84.        android:id="@+id/quit"
  85.        android:layout_width="fill_parent"
  86.        android:layout_height="wrap_content"
  87.        android:text="Close Application" />
  88.  
  89.     <GridLayout
  90.        android:id="@+id/state"
  91.        android:layout_width="match_parent"
  92.        android:layout_height="wrap_content" >
  93.     </GridLayout>
  94.  
  95. </LinearLayout>
  96.  
  97.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


Can someone help me? I think it shouldn't be that hard ;)

Thank you a lot


Regards
JediMind91
Freshman
Freshman
 
Posts: 3
Joined: Sun Feb 12, 2012 7:28 pm

Top

Re: My Application starts - crashes (No Errors)

Postby Phyll » Thu Feb 16, 2012 5:59 am

Hi JediMind,

It looks like it stops on this line:

textState = (TextView)findViewById(R.id.state);

because state has been changed to a GridLayout, just like the logcat says, on line 30.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 12 guests