【发布时间】:2014-06-27 11:42:45
【问题描述】:
我尝试制作一个简单的应用程序。 这是我在 android 中的第一个应用程序,但我对 java 并不陌生。 该应用程序只有一个自定义背景和主屏幕上播放的声音(歌曲)。 它构建成功。完全没有错误..!!! 我什至处理了警告..
但是这个应用程序不能在设备上运行(我不使用模拟器..!!) 它说,“不幸的是 [appname] 已停止”..
为什么????
这是我的java代码..:
package com.exmple.worth;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
MediaPlayer bfmv = MediaPlayer.create(MainActivity.this, R.raw.saf ) ;
Button b1 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.b1) ;
bfmv.start() ;
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
bfmv.stop() ;
}
});
}
}
这是我的 xml 文件:
<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"
tools:context="${packageName}.${activityClass}"
android:background="@drawable/qwe" >"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:text="Pause" />
</RelativeLayout>
这里是 Android 清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exmple.worth"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.exmple.worth.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
你的 logcat 应该显示它为什么崩溃了?
-
发布包含崩溃时引发的异常的 LOGCAT
-
你的 logcat 过滤了吗?
-
Logcat ..??先生,绝对没有错误......
标签: java android xml eclipse android-layout