0

I just started programming android. As the title says my app stops after i launch it. It would be nice if u could help me. If u need any other code or something, just tell me i will post it as soon as i can.

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
       final MediaPlayer mp;
       Button one; 

        mp = MediaPlayer.create(this, R.raw.button);
        one = (Button)this.findViewById(R.id.button1);

        one.setOnClickListener(new View.OnClickListener() {

           @Override
           public void onClick(View v) {
               // TODO Auto-generated method stub

               mp.start();
           }
       });


    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}

}
Umit Kaya
  • 5,771
  • 3
  • 38
  • 52
  • 1
    Please post your Logcat.. – Lal May 12 '14 at 18:16
  • Try one thing...Copy all your contents in `fragment_main.xml` to `activity_main.xml` and try running the app.. – Lal May 12 '14 at 18:17
  • Please read the answer to the question linked at the top of this page. If you still have problems, let us know and we can help from there. – Code-Apprentice May 12 '14 at 18:24
  • 05-12 14:29:35.672: E/StrictMode(952): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. i found the stack trace but i dont know what to do with it :/ – Code or Not May 12 '14 at 21:06

0 Answers0