I am trying to learn some java/android development, but I'm really struggling with the basics.
My code looks like this.
package com.example.app_james3;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
MediaPlayer media=MediaPlayer.create(this, R.raw.button);
media.start(); // THIS LINE IS GIVING ERROR: Syntax error on token "start", Identifier expected after this token
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
Can anyone offer advice to get this very simple line working? I've copied others code, so I am fairly sure the syntax is correct.