简体   繁体   English

我想在android中实现SeekBar,但是当我运行以下程序时,我的模拟器显示错误“不幸的是SeekBar已停止”

[英]I want to implement SeekBar in android ,But when i run the below program my emulator shows error that “Unfortunately SeekBar has been stopped”

When I change the seekbar in spite of showing the value it says "unfortunately SeekBarActivity has been stopped" 当我更改搜索栏时尽管显示了该值,但显示“不幸的是,SeekBarActivity已停止”

activity_main.xml file: activity_main.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 MainActivity.java文件

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();
        }
    });



}
}

my Stack trace: 我的堆栈跟踪:

      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

Where I am wrong?? 我哪里错了? Any help will b appreciated, thanks in advance. 任何帮助将不胜感激,在此先感谢。 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”

you are calling tv.setText(pro); 您正在呼叫tv.setText(pro); when pro is an int value int argument in setText is an string id such as R.string.some_id when you call it with an int and Android can not find string resource with an id equals to pro value you get Resource not found exception. 如果pro是int值,则setText中的int参数是字符串ID(例如R.string.some_id当您使用int调用它时,Android无法找到ID等于pro值的字符串资源,则会出现Resource not found异常。 you should change it to: 您应该将其更改为:

    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
        }

    });

My guess is that the mediastream isn't keeping up with the position of the seeker. 我的猜测是媒体流跟不上搜寻者的位置。

When you update the seeker, make sure the content you're trying to seek to is already in queue. 更新搜索程序时,请确保您要搜索的内容已在队列中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在android studio中运行程序时出现错误“不幸的是,我的应用程序已停止” - There is an error “unfortunately, my application has stopped” when i run my program in android studio Android SeekBar应用程序-不幸的是,该项目已停止 - Android SeekBar Application - Unfortunately, project has stopped 不幸, <your app> 已停止,而我正在尝试在我的android模拟器中运行它。 如何解决呢? - unfortunately, <your app> has stopped while i am trying it run it in my android emulator. how to solve this? 不幸的是,当我要推送片段时,Android已停止 - Android unfortunately has stopped when I want to push fragment 每当我在模拟器上运行该应用程序时,它都会说不幸的是该应用程序已停止工作并且日志如下所示 - whenever i run the app on emulator it says unfortunately the app has stopped working and the log reads as below 每当我在模拟器上运行该应用程序时,它都会说不幸的是该应用程序已停止工作并且日志读取以下行 - whenever i run the app on emulator it says unfortunately the app has stopped working and the log reads the below lines 当我尝试运行我的Android模拟器时,我收到“不幸的是启动器已停止”消息 - When i am trying to run my android simulator i am getting the “Unfortunately launcher has stopped ” message 当我在android虚拟设备上运行mediaplayer应用时,出现错误消息,表示我的应用已停止。 - When I run mediaplayer app on android virtual device error comes saying that unfortunately my app has stopped. 不幸的是,当使用模拟器运行时,已停止了应用程序android - unfortunately has stopped app android when run with emulator 我无法在android studio模拟器中甚至在手机中作为运行设备来运行该应用程序。 不幸的是,数据库程序已停止 - I wouldn't able to run the app in android studio emulator and even in my phone as running devices. the database Program is unfortunately stopped
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM