gpt4 book ai didi

java - 使用进度条的问题

转载 作者:行者123 更新时间:2023-12-02 09:22:27 25 4
gpt4 key购买 nike

我正在尝试使用进度条来设置 TextView 的值。我有以下代码,但是每当您触摸进度条时,应用程序就会崩溃。我的手机给出的错误消息是:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“void android.widget.TextView.setText(int)”3)

ISOreadout 是 TextView

这是代码:

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.camera2.*;
import android.os.Bundle;
import android.view.*;
import android.util.*;
import android.widget.*;


public class MainActivity extends AppCompatActivity {

ImageButton imageButton;
Integer width, height;
boolean focusable;
View popupView;
LayoutInflater inflater;
SeekBar ISOseekbar;
TextView ISOreadout;

public void mainUI(){


ISOseekbar = findViewById(R.id.ISOseekbar);
ISOseekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
ISOreadout.setText(progress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});




}


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainUI();


}}

编辑初始化变量后,应用程序现在崩溃并出现以下错误:

at android.content.res.Resources.getText(Resources.java:360)
at android.content.res.MiuiResources.getText(MiuiResources.java:97)
at android.widget.TextView.setText(TextView.java:5856)
at com.example.startrailscamera.MainActivity$2.onProgressChanged(MainActivity.java:59)
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:95)
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:1298)
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:1353)
at android.widget.ProgressBar.setProgressInternal(ProgressBar.java:1418)
at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:869)
at android.widget.AbsSeekBar.startDrag(AbsSeekBar.java:826)
at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:773)
at android.view.View.dispatchTouchEvent(View.java:12527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2662)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:444)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830)
at android.app.Activity.dispatchTouchEvent(Activity.java:3465)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:402)
at android.view.View.dispatchPointerEvent(View.java:12768)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5272)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5072)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4587)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4640)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4606)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4746)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4614)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4803)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4587)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4640)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4606)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4614)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4587)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7315)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7284)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7245)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7421)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:249)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

最佳答案

您需要初始化 TextView ,尝试将此代码放入 mainUI 中:

ISOreadout = findViewById(R.id.ISOreadout); // make sure this is the right id

关于java - 使用进度条的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596063/

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