Я пытаюсь использовать индикатор выполнения, чтобы установить значение текстового представления. У меня есть следующий код, однако всякий раз, когда вы касаетесь индикатор выполнения, приложение вылетает. Сообщение об ошибке, которое выдает мой телефон: 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)