按下按钮时我正在播放声音。我之前使用过此代码,但现在在我的新项目中,我的应用程序崩溃了。
这是我的代码:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.green.philip.budgetplannerdroid"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.parse:parse-android:1.12.0'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.android.support:multidex:1.0.1'
}
这是我的日志:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.sound1);
Button play_button = (Button)this.findViewById(R.id.ring);
play_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mp.start();
}
});
}