0

我的程序有问题...我想做一个简单的搜索栏,在更改吐司时显示其值。

这是我的代码:

SeekBar seek = (SeekBar) findViewById(R.id.seekBar1);

seek.setOnSeekBarChangeListener( new OnSeekBarChangeListener() {

 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
      Toast.makeText(getApplicationContext(), progress, Toast.LENGTH_SHORT).show();
 }

  public void onStartTrackingTouch(SeekBar arg0) {

  }

  public void onStopTrackingTouch(SeekBar arg0) {

  }
  });

这是我的错误(日志):

 06-14 22:18:16.330: E/AndroidRuntime(991): FATAL EXCEPTION: main
06-14 22:18:16.330: E/AndroidRuntime(991): android.content.res.Resources$NotFoundException: String resource ID #0x1
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.content.res.Resources.getText(Resources.java:229)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.Toast.makeText(Toast.java:265)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.neneinc.shakemute.MainActivity$2.onProgressChanged(MainActivity.java:48)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.SeekBar.onProgressRefresh(SeekBar.java:91)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:660)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.ProgressBar.refreshProgress(ProgressBar.java:672)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.ProgressBar.setProgress(ProgressBar.java:719)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:424)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:362)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.View.dispatchTouchEvent(View.java:7127)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.View.dispatchPointerEvent(View.java:7307)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3174)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3119)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4155)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4134)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4226)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:163)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4205)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4245)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.Choreographer.doCallbacks(Choreographer.java:555)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.Choreographer.doFrame(Choreographer.java:523)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.os.Handler.handleCallback(Handler.java:615)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.os.Looper.loop(Looper.java:137)
06-14 22:18:16.330: E/AndroidRuntime(991):  at android.app.ActivityThread.main(ActivityThread.java:4745)
06-14 22:18:16.330: E/AndroidRuntime(991):  at java.lang.reflect.Method.invokeNative(Native Method)
06-14 22:18:16.330: E/AndroidRuntime(991):  at java.lang.reflect.Method.invoke(Method.java:511)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-14 22:18:16.330: E/AndroidRuntime(991):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-14 22:18:16.330: E/AndroidRuntime(991):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

Don't pass the progress variable directly to makeText(Context, int, int) because that version of the method expects a resource id (an int value corresponding to an entry in the R autogenerated file). Pass String.valueOf(progress) instead, to convert it to a String and call makeText(Context, String, int). In other words, replace this:

Toast.makeText(getApplicationContext(), progress, Toast.LENGTH_SHORT).show();

with this:

 Toast.makeText(getApplicationContext(), String.valueOf(progress), Toast.LENGTH_SHORT).show();
于 2013-06-14T22:26:14.933 回答