Я хочу реализовать SeekBar в Android, но когда я запускаю нижеприведенную программу, мой эмулятор выдает ошибку «К сожалению, SeekBar остановлен» - PullRequest
0 голосов
/ 05 сентября 2018

Когда я изменяю панель поиска, несмотря на отображение значения, он говорит: «К сожалению, SeekBarActivity остановлен»

файл_действия.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<SeekBar
    android:id="@+id/sb"
    android:layout_width="match_parent"
    android:layout_height="63dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="178dp"
    tools:layout_editor_absoluteX="99dp"
    tools:layout_editor_absoluteY="201dp" />

<TextView
    android:id="@+id/tv"
    android:layout_width="326dp"
    android:layout_height="64dp"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/sb"
    android:layout_marginStart="14dp"
    android:text=""
    tools:ignore="UnknownId"
    tools:layout_editor_absoluteX="99dp"
    tools:layout_editor_absoluteY="219dp"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="14dp" />

<RatingBar
    android:id="@+id/rb"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="53dp" />

</RelativeLayout>

MainActivity.java file

package com.example.mypc.seekbarapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;

public class MainActivity extends AppCompatActivity {
TextView tv;
SeekBar sb;
RatingBar rb;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv=(TextView) findViewById(R.id.tv);
    sb=(SeekBar)findViewById(R.id.sb);
    rb=(RatingBar)findViewById(R.id.rb);
    sb.setMax(100);
    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
       int pro=0;
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            pro=progress;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
          tv.setText(pro);
            //  
Toast.makeText(MainActivity.this,pro,Toast.LENGTH_LONG).show();
        }

    });
    rb.setOnRatingBarChangeListener(new 
RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, 
boolean fromUser) {
   Toast.makeText(MainActivity.this,
   String.valueOf(rating),Toast.LENGTH_LONG)
   .show();
        }
    });



}
}

мой след стека:

      at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:143)
    at android.os.Looper.loop(Looper.java:122)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
    .run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
09-04 17:37:04.097 2773-2773/? I/Process: Sending signal. PID: 2773 SIG: 
9

Где я не прав ?? Любая помощь будет оценена, спасибо заранее. «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «» «»

Ответы [ 2 ]

0 голосов
/ 05 сентября 2018

Я предполагаю, что медиастрим не поспевает за позицией ищущего.

При обновлении искателя убедитесь, что контент, который вы пытаетесь найти, уже находится в очереди.

0 голосов
/ 05 сентября 2018

вы звоните tv.setText(pro);, когда pro - это значение int, аргумент int в setText - это строковый идентификатор, такой как R.string.some_id, когда вы вызываете его с помощью int, и Android не может найти строковый ресурс с идентификатором, равным pro значению, которое вы Исключение не найден. Вы должны изменить его на:

    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int pro=0;
        String proStr = "";
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            pro=progress;
            proStr = String.valueOf(pro);// convert int to String
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
          tv.setText(proStr); // use String instead of int
          Toast.makeText(MainActivity.this, proStr, Toast.LENGTH_LONG).show(); // use String instead of int
        }

    });
...