gpt4 book ai didi

java - 我在 android studio 中运行代码时遇到错误

转载 作者:行者123 更新时间:2023-12-01 16:26:06 24 4
gpt4 key购买 nike

我不知道为什么在使用 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);
}
}

最佳答案

尝试改变

    ArrayList<Song> songs;

到此

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

或者在onCreate中定义它...

songs= new ArrayList<>();

关于java - 我在 android studio 中运行代码时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62144407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com