繁体   English   中英

在 android studio 中运行代码时出现错误

[英]I am having an error when run code in android studio

我不知道为什么在使用 android studio 的模拟器中运行此代码时会出错。

详细错误: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, (无效的))

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);
    }
}

尝试改变

    ArrayList<Song> songs;

对此

    ArrayList<Song> songs= new ArrayList<>();

或在 onCreate 中定义它...

songs= new ArrayList<>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM