java.lang.numberformatexception:对于输入字符串:“7534eed19a5ec9a5039315d72a24b063.mp4”

bjg7j2ky  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(179)

**已关闭。**此问题需要调试详细信息。它目前不接受答案。
**想要改进此问题?**更新问题,使其位于堆栈溢出主题上。

昨天关门了。
改进这个问题
我正在尝试获取视频文件的持续时间,但它抛出了java.lang.numberformatexception错误。请帮助我修复此错误
com.wk.videoplayer.videoadapter.onbindviewholder(videoadapter.java:39)com.wk.videoplayer.videoadapter.onbindviewholder(videoadapter.java:20)
videoadapter代码中的第39行:double毫秒=double.parsedouble(videofiles.get(position.getduration());
视频适配器代码中的第20行:
这是完整的视频适配器代码

package com.wk.videoplayer;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.io.File;
import java.util.ArrayList;
import java.util.Locale;

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.MyViewHoler> {

**here is my VideoAdapter code**

    public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.MyViewHoler> {
        private Context mcontext;
        static ArrayList<VideoFiles> videoFiles;
        View view;
        public VideoAdapter(Context mcontext, ArrayList<VideoFiles> videoFiles) {
            this.mcontext = mcontext;
            this.videoFiles = videoFiles;
        }

        @NonNull
        @Override
        public MyViewHoler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            view = LayoutInflater.from(mcontext).inflate(R.layout.video_item, parent, false);
            return new MyViewHoler(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHoler holder, int position) {
            holder.fileName.setText(videoFiles.get(position).getTitle());
            // the erros is here in the below line, the below line is line:39
            double milliSeconds = Double.parseDouble(videoFiles.get(position).getDuration());
            holder.videoDuration.setText(timeConversion((long) milliSeconds));
            //holder.videoDuration.setText("05:00");

            Glide.with(mcontext)
                    .load(new File(videoFiles.get(position).getPath()))
                    .into(holder.thumbnail);
            holder.itemView.setOnClickListener(view -> {
                Intent intent = new Intent(mcontext, PlayerActivity.class);
                intent.putExtra("position", position);
                intent.putExtra("sender", "FilesIsSending");
                mcontext.startActivity(intent);
            });
        }

        @Override
        public int getItemCount() {
            return videoFiles.size();
        }

        public class MyViewHoler extends RecyclerView.ViewHolder {
            ImageView thumbnail, menuMore;
            TextView fileName, videoDuration;
            public MyViewHoler(@NonNull View itemView) {
                super(itemView);
                thumbnail = itemView.findViewById(R.id.thumbnail);
                menuMore = itemView.findViewById(R.id.menu_more);
                fileName = itemView.findViewById(R.id.video_file_name);
                videoDuration = itemView.findViewById(R.id.video_duration);
            }
        }

        public String timeConversion (long value) {
            String videoTime;
            int duration = (int) value;
            int hours = (duration/3600000);
            int minutes = (duration/60000) % 60000;
            int seconds = duration%60000/1000;
            if (hours > 0)
            {
                videoTime = String.format(Locale.US,"%02d:%02d:%02d:", hours, minutes, seconds);
            }
            else
            {
                videoTime = String.format(Locale.US,"%02d:%02d", minutes, seconds);
            }
            return videoTime;
        }

    }

以下是videofiles.java代码:

package com.wk.videoplayer;

public class VideoFiles {
    private String id;
    private String path;
    private String title;
    private String filename;
    private String size;
    private String dateAdded;
    private String duration;

    public VideoFiles(String id, String path, String title, String filename, String size, String dateAdded, String duration) {
        this.id = id;
        this.path = path;
        this.title = title;
        this.filename = filename;
        this.size = size;
        this.dateAdded = dateAdded;
        this.duration = duration;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public String getDateAdded() {
        return dateAdded;
    }

    public void setDateAdded(String dateAdded) {
        this.dateAdded = dateAdded;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题