空对象引用上的虚拟方法“void org.florescu.android.rangeseekbar.RangeSeekBar.setRangeValues(java.lang.Number, java.lang.Number)”

virtual method 'void org.florescu.android.rangeseekbar.RangeSeekBar.setRangeValues(java.lang.Number, java.lang.Number)' on a null object reference

提问人:Hygge 提问时间:8/10/2023 更新时间:8/10/2023 访问量:3

问:

我正在使用这个应用程序,但在使用应用程序时,请关闭我的应用程序。我花了很长时间,但我不明白它是什么。

它只想使对象为 null。但是哪一个呢?我不知道哪个对象应该是空的。如果你能帮助我解决这个问题,我会很高兴。

错误行

rangeSeekBar.setRangeValues(0, duration);

错误代码

D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yalan.videokes, PID: 17640
    **java.lang.NullPointerException: Attempt to invoke virtual method 'void org.florescu.android.rangeseekbar.RangeSeekBar.setRangeValues(java.lang.Number, java.lang.Number)' on a null object reference
        at com.yalan.videokes.TrimActivity$2.onPrepared(TrimActivity.java:110)**
        at android.widget.VideoView$2.onPrepared(VideoView.java:499)
        at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:3420)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:225)
        at android.app.ActivityThread.main(ActivityThread.java:7563)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

TrimActivity.java


import java.io.File;
import java.util.Arrays;

public class TrimActivity extends AppCompatActivity {
    Uri uri;
    String filePrefix;
    int duration;
    ImageView imageView;
    TextView textViewLeft,textViewRight;
    VideoView videoView;

    RangeSeekBar rangeSeekBar;
    private String filePath;
    private static final String FILEPATH = "filepath";
    String[] command;

    boolean isPlaying = false;
    File dest;
    String original_path;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trim);

        imageView = findViewById(R.id.imageView);
        textViewLeft = findViewById(R.id.tvLeft);
        textViewRight = findViewById(R.id.tvRight);
        videoView = findViewById(R.id.videoView);


        Intent i = getIntent();
        if(i!=null) {
            String imagePath = i.getStringExtra("uri");
            uri = Uri.parse(imagePath);
            isPlaying = true;
            videoView.setVideoURI(uri);
            videoView.start();
        }


        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isPlaying) {
                    imageView.setImageResource(R.drawable.ic_play);
                    videoView.pause();
                    isPlaying = false;
                } else {
                    videoView.start();
                    imageView.setImageResource(R.drawable.ic_pause);
                    isPlaying = true;
                }
            }
        });

        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                **videoView.start();
                duration = mediaPlayer.getDuration() / 1000;
                textViewLeft.setText("00:00:00");
                textViewRight.setText(getTime(mediaPlayer.getDuration() / 1000));
                mediaPlayer.setLooping(true);
                rangeSeekBar.setRangeValues(0, duration);
                rangeSeekBar.setSelectedMaxValue(duration);
                rangeSeekBar.setSelectedMinValue(0);
                rangeSeekBar.setEnabled(true);**

                rangeSeekBar.setOnRangeSeekBarChangeListener(new RangeSeekBar.OnRangeSeekBarChangeListener() {
                    @Override
                    public void onRangeSeekBarValuesChanged(RangeSeekBar bar, Object minValue, Object maxValue) {
                        videoView.seekTo(((int)minValue*1000));
                        textViewLeft.setText(getTime((int)bar.getSelectedMinValue()));
                        textViewRight.setText(getTime((int)bar.getSelectedMaxValue()));
                    }
                });

                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if(videoView.getCurrentPosition() >= rangeSeekBar.getSelectedMaxValue().intValue()*1000) {
                            videoView.seekTo(rangeSeekBar.getSelectedMinValue().intValue()*1000);
                        }
                    }
                },1000);

            }
        });



    }

    private String getTime(int seconds) {
        int hr = seconds/3600;
        int rem = seconds%3600;
        int mn = rem/60;
        int sec = rem%60;

        return String.format("%02d",hr)+" "+ String.format("%02d",mn)+""+String.format("%02d",sec);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if(item.getItemId() == R.id.TrimVideo) {
            AlertDialog.Builder alert = new AlertDialog.Builder(TrimActivity.this);
            LinearLayout linearLayout = new LinearLayout(TrimActivity.this);
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(50,0,50,100);
            EditText input = new EditText(TrimActivity.this);
            input.setLayoutParams(lp);
            input.setGravity(Gravity.TOP|Gravity.START);
            input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            linearLayout.addView(input,lp);

            alert.setMessage("Set video name");
            alert.setTitle("videoname");

            alert.setView(linearLayout);
            alert.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();


                }
            });


            alert.setPositiveButton("submit", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    String filePrefix = input.getText().toString();

                    trimVideo(rangeSeekBar.getSelectedMinValue().intValue()*1000,rangeSeekBar.getSelectedMaxValue().intValue()*1000,filePrefix);
                    finish();
                    dialogInterface.dismiss();
                }
            });
            alert.show();


        }
        return super.onOptionsItemSelected(item);

    }

    private void trimVideo(int startMs, int endMs, String fileName) {
        File folder = new File(Environment.getExternalStorageDirectory() + "/VideoEditor");
        if (!folder.exists()) {
            folder.mkdir();
        }
        filePrefix = fileName;

        String fileExt = ".mp4";
        System.out.println("audio"+fileExt);
        dest = new File(folder, filePrefix + fileExt);
        original_path = getRealPathFromUri(getApplicationContext(), uri);

        duration = (endMs - startMs) / 1000;
        filePath = dest.getAbsolutePath();

        command = new String[]{"-ss", "" + startMs / 1000, "-y", "-i", original_path, "-t", "" + (endMs - startMs) / 1000, "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};
        execffmpeqBinary(command);
        Toast.makeText(this,"Video Trimmed Successfulled",Toast.LENGTH_LONG).show();
    }

    private String getRealPathFromUri(Context context, Uri containturi) {
        Cursor cursor = null;
        try {
            String[] proj = {MediaStore.Images.Media.DATA};
            cursor = context.getContentResolver().query(containturi,proj,null,null,null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        } finally {
            if (cursor!= null) {
                cursor.close();
            }

        }
    }

    private void execffmpeqBinary(String[] command) {
        Config.enableLogCallback(new LogCallback() {
            @Override
            public void apply(LogMessage message) {
                Log.e(Config.TAG,message.getText());
            }
        });
        Config.enableStatisticsCallback(new StatisticsCallback() {
            @Override
            public void apply(Statistics newStatistics) {
                Log.e(Config.TAG, String.format("frame %d, time %d",
                        newStatistics.getVideoFrameNumber(),
                        newStatistics.getTime()));

                Log.d(TAG,"started command: ffmpeq" + Arrays.toString(command));

                long executionId = FFmpeg.executeAsync(command, new ExecuteCallback() {
                    @Override
                    public void apply(long executionId, int returnCode) {
                        if (returnCode == RETURN_CODE_SUCCESS) {
                            //  progressDialog.dismiss();
                            Log.d(Config.TAG, "finished command: ffmpeg" + Arrays.toString(command));

                        } else if (returnCode == RETURN_CODE_CANCEL) {
                            Log.e(Config.TAG, "Async command execution canceled by user");
                        } else {
                            Log.e(Config.TAG, String.format("Async command execution failed with returncode = %d", returnCode));
                        }
                    }
                });

            }
        });
    }


}

android null

评论


答: 暂无答案