I dont know why it has error when run this code in emulator with android studio.
The detail error: SA Emulator: emulator: INFO: QtLogger.cpp:68: Critical: Uncaught TypeError: Cannot read property 'update' of undefined (qrc:/html/js/location-mock-web-channel.js:130, (null))
package com.example.zingmp3;
import androidx.appcompat.app.AppCompatActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private Button nextButton, previousButton, playButton, pauseButton;
private SeekBar seekBar;
private TextView timeCurrent, timeTotal, nameSong;
private int index;
private int position = 3;
private Handler handler;
ArrayList<Song> songs;
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findById();
addSong();
mediaPlayer = MediaPlayer.create(MainActivity.this, songs.get(position).getFile());
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mediaPlayer.start();
}
});
}
public void findById() {
this.nextButton = findViewById(R.id.playButton);
this.previousButton = findViewById(R.id.previousButton);
this.playButton = findViewById(R.id.playButton);
this.timeCurrent = findViewById(R.id.timeCurrent);
this.timeTotal = findViewById(R.id.totalTime);
this.seekBar = findViewById(R.id.seekBar);
this.nameSong = findViewById(R.id.nameSong);
}
private void addSong() {
Song song1 = new Song("Mot Cu Lua", R.raw.song1);
Song song2 = new Song("So rang anh con yeu em", R.raw.soranganhyeuem);
Song song3 = new Song("Tinh sau thien thu muon loi", R.raw.tinhsauthienthu);
songs.add(song1);
songs.add(song2);
songs.add(song3);
}
}
try to change
ArrayList<Song> songs;
to this
ArrayList<Song> songs= new ArrayList<>();
or define it in onCreate...
songs= new ArrayList<>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.