[英]error: MainActivity is not abstract and does not override abstract method onFABProgressAnimationEnd() in FABProgressListener
I'm new on android and didn't know what this error, about abstract class我是 android 新手,不知道这个错误是什么,关于抽象类
I've trying to figure out what solution of my problem, i tried implement this but still didn't works.我试图找出我的问题的解决方案,我尝试实现它,但仍然没有用。 here my source code.这是我的源代码。
package com.test.streaming;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
// need more lib
import android.media.MediaPlayer;
import android.util.Log;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
// loading
import com.github.jorgecastilloprz.FABProgressCircle;
import com.github.jorgecastilloprz.listeners.FABProgressListener;
import java.io.IOException;
and i think here the problem我认为问题就在这里
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener, FABProgressListener{
// Deklarasi variable utama
// alamat streaming controhnya
//private String url_radio= "http://usa8-vn.mixstream.net:8138";
//
private String url_radio= "http://cloudstreaming.mramedia.com:8000/live";
private FABProgressCircle fabProgressCircle;
private ProgressBar playSeekBar;
private TextView tvRadioUrl;
private Button buttonPlay;
private Button buttonStopPlay;
private MediaPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
fabProgressCircle = (FABProgressCircle) findViewById(R.id.fab);
/* untuk membuat bar */
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
fabProgressCircle.show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
/* end untuk membuaat bar */
// define our radio function
initializeUIElements();
initializeMediaPlayer();
}
// inisiasi UI ELEMET
private void initializeUIElements() {
playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
playSeekBar.setMax(100);
playSeekBar.setVisibility(View.INVISIBLE);
playSeekBar.setIndeterminate(true);
buttonPlay = (Button) findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
buttonStopPlay = (Button) findViewById(R.id.buttonStop);
buttonStopPlay.setEnabled(false);
buttonStopPlay.setOnClickListener(this);
//tvRadioUrl = (TextView) findViewById(R.id.textViewRadioUrl);
//tvRadioUrl.setText("Radio url : "+url_radio);
}
// button onClick
public void onClick(View v) {
if (v == buttonPlay) {
startPlaying();
} else if (v == buttonStopPlay) {
stopPlaying();
}
}
private void startPlaying() {
buttonStopPlay.setEnabled(true);
buttonPlay.setEnabled(false);
playSeekBar.setVisibility(View.VISIBLE);
player.prepareAsync();
// loading (still not working yet)
// mImageView = (ImageView) findViewById(R.id.imageLoadingPlayer);
// Drawable mWaveDrawable = new WaveDrawable(this, R.drawable.ic_launcher_background);
// // Use as common drawable
// mImageView.setImageDrawable(mWaveDrawable);
//
//
// mWaveDrawable.setLevel(1);
// mWaveDrawable.setLevel(11);
//mWaveDrawable.setLevel(500);
// loading
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
sendNotif("Grey, LÉON", "Want You Back (feat. LÉON)");
Log.d("MyDebug", "Notif Sent..");
//
}
});
}
private void stopPlaying() {
Log.d("MyDebug", "Stop Button Pressed.");
if (player.isPlaying()) {
player.stop();
player.release();
initializeMediaPlayer();
}
buttonPlay.setEnabled(true);
buttonStopPlay.setEnabled(false);
playSeekBar.setIndeterminate(true);
playSeekBar.setVisibility(View.INVISIBLE);
}
private void initializeMediaPlayer() {
player = new MediaPlayer();
Log.d("MyDebug", "initializeMediaPlayer() " );
try {
player.setDataSource(url_radio);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.d("MyDebug", "stream address set " );
player.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// percent can be something awkward like "-2147483648" on a live source. Just clamp it.
if (percent < 0) {
percent = 0;
}
else if (percent > 100) {
percent = 100;
}
// debug
Log.d("MyDebug", "Buffering " + percent);
playSeekBar.setIndeterminate(false);
playSeekBar.setSecondaryProgress(100);
}
});
}
@Override
protected void onPause() {
super.onPause();
if (player.isPlaying()) {
// player.stop();
}
}
public void sendNotif(String artist, String song){
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(android.R.drawable.ic_dialog_alert);
Intent intent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.journaldev.com/"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent2, 0);
//HERE ARE YOUR BUTTONS
builder.addAction(R.drawable.ic_audiotrack_black_24dp, "BUTTON 1",pendingIntent);
builder.addAction(R.drawable.ic_audiotrack_black_24dp, "BUTTON 2",pendingIntent);
// Apply the media style template
//builder.setStyle(new Notification.MediaStyle());
// builder.setContentIntent(pendingIntent);
builder.setContentTitle(artist);
builder.setContentText(song);
builder.setSubText("Now Playing");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Will display the notification in the notification bar
notificationManager.notify(1, builder.build());
}
/* fungsi bawaat template */
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_streaming) {
// Handle the camera action
} else if (id == R.id.nav_share) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
}
giving error:给出错误:
error: MainActivity is not abstract and does not override abstract method onFABProgressAnimationEnd() in FABProgressListener
error: MainActivity is not abstract and does not override abstract method onFABProgressAnimationEnd() in FABProgressListener错误:MainActivity 不是抽象的,并且不会覆盖 FABProgressListener 中的 onFABProgressAnimationEnd() 抽象方法
=> Because you have implemented FABProgressListener
: => 因为你已经实现了FABProgressListener
:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener, FABProgressListener{
...
...
}
Since the MainActivity class is not an abstract class but you have implemented FABProgressListner interface, so you have to override all of its methods:由于 MainActivity 类不是抽象类,但您已经实现了FABProgressListner接口,因此您必须覆盖其所有方法:
public interface FABProgressListener {
void onFABProgressAnimationEnd();
}
Seems you are new to the Java world as well, also on another comment if you read library document carefully then you would have got answer:似乎您也是 Java 世界的新手,如果您仔细阅读库文档,那么在另一条评论中也会得到答案:
@Override public void onFABProgressAnimationEnd() {
Snackbar.make(fabProgressCircle, R.string.cloud_upload_complete, Snackbar.LENGTH_LONG)
.setAction("Action", null)
.show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.