0

我是 Android 编程的初学者,正在制作一个音乐和视频播放器,它已经编写了大部分程序,但是当模拟器执行时,我收到以下错误:

不幸的是,FlagPlayer 已经停止

我对这个主题做了很多研究,但我找不到任何可以解决我的问题的东西。我希望你能帮助我。

这是我的主要课程:

package tcc.etec.FlagPlayer;

import android.R.integer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

   private Button btMusica;
   private Button btArtista;
   private Button btAlbum;
   private Button btVideo;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      acaobutton();
   }

    public void acaobutton(){
      btMusica = (Button)findViewById(R.id.btmusica);
      btMusica.setOnClickListener((OnClickListener) this);

      btArtista = (Button)findViewById(R.id.btartista);
      btArtista.setOnClickListener((OnClickListener) this);

      btAlbum = (Button)findViewById(R.id.btalbuns);
      btAlbum.setOnClickListener((OnClickListener) this);

      btVideo= (Button)findViewById(R.id.btvideo);
      btVideo.setOnClickListener((OnClickListener) this);
  }

   public void onClick(View v){
      if (v.getId()==R.id.btmusica){
         Intent intent = new Intent(MainActivity.this, ListaMusicaActivity.class);
      }else if (v.getId()==R.id.btartista){
         Intent intent = new Intent(MainActivity.this, ListaArtistaActivity.class);
      }else if (v.getId()==R.id.btalbuns){
        Intent intent = new Intent(MainActivity.this, ListaAlbumActivity.class);
      }else if (v.getId()==R.id.btvideo){
        Intent intent = new Intent(MainActivity.this, ListaVideoActivity.class);
    }
   }

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=".MainActivity" >

<Button
    android:id="@+id/btmusica"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="19dp"
    android:text="Musicas" />

<Button
    android:id="@+id/btartista"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btmusica"
    android:layout_alignBottom="@+id/btmusica"
    android:layout_alignParentRight="true"
    android:layout_marginRight="14dp"
    android:text="Artistas" />

<Button
    android:id="@+id/btalbuns"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="66dp"
    android:text="Albuns" />

<Button
    android:id="@+id/btvideo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btalbuns"
    android:layout_alignBottom="@+id/btalbuns"
    android:layout_alignRight="@+id/btartista"
    android:text="Videos" />

和 AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tcc.etec.FlagPlayer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".tcc.etec.FlagPlayer.activity_main"
         android:label="@string/app_name">
        <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".tcc.etec.FlagPlayer.ListaMusicaActivity" >
         <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name=".tcc.etec.FlagPlayer.MusicPlayerActivity" >
          <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>

</manifest>
4

1 回答 1

0

尝试更换您的:

public void acaobutton(){
  btMusica = (Button)findViewById(R.id.btmusica);
  btMusica.setOnClickListener((OnClickListener) this);

  btArtista = (Button)findViewById(R.id.btartista);
  btArtista.setOnClickListener((OnClickListener) this);

  btAlbum = (Button)findViewById(R.id.btalbuns);
  btAlbum.setOnClickListener((OnClickListener) this);

  btVideo= (Button)findViewById(R.id.btvideo);
  btVideo.setOnClickListener((OnClickListener) this);
}

至:

public void acaobutton(){
  btMusica = (Button)findViewById(R.id.btmusica);
  btMusica.setOnClickListener((OnClickListener) getBaseContext());

  btArtista = (Button)findViewById(R.id.btartista);
  btArtista.setOnClickListener((OnClickListener) getBaseContext());

  btAlbum = (Button)findViewById(R.id.btalbuns);
  btAlbum.setOnClickListener((OnClickListener) getBaseContext());

  btVideo= (Button)findViewById(R.id.btvideo);
  btVideo.setOnClickListener((OnClickListener) getBaseContext());
}
于 2013-11-11T01:26:13.150 回答