10086转008
2014-12-04 03:36
采纳率: 66.7%
浏览 4.4k

【android新手】进度条progressBar无法运行问题

//xml布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"

 <TextView 
     android:layout_width="fill_parent" android:layout_height="wrap_content"
     android:text="进度条"
     />    
 <progressBar
     android:layout_width="wrap_content" android:layout_height="wrap_content"
 />
 <progressBar
     style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content"
     android:layout_height="wrap_content"
 />
 <progressBar
     style="?android:attr/progressBarStyleSmall" android:layout_width="wrap_content"
     android:layout_height="wrap_content"
 />
 <progressBar
     style="?android:attr/progressBarStyleHorizontal" android:layout_width="200dip"
     android:layout_height="wrap_content" android:id="@+id/progressBarHorizontal"
     android:max="100"
 />
 <Button 
     android:id="@+id/btnup" android:layout_width="wrap_content"
     android:layout_height="wrap_content" android:text="增加进度条"
     android:textSize="20sp"
     />
 <Button 
     android:id="@+id/btndown" android:layout_width="wrap_content"
     android:layout_height="wrap_content" android:text="减少进度条"
     android:textSize="20sp"
     />

//Java代码
package carol.progressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener
{
private ProgressBar bar;
private Button btnup;
private Button btndown;
private int count=0;
private int current=50;
private String show;
private ProgressBar progressBarHorizontal;
@Override
public void onClick(View view)
{
switch (view.getId())
{
// 处理“增加进度"按钮事件
case R.id.btnup:
count+=5;
if(count<=bar.getMax())
bar.setProgress(count);
current=bar.getProgress();
show="当前进度为: "+ String.valueOf(current);
Toast.makeText(getBaseContext(), show, Toast.LENGTH_LONG).show();
break;
// 处理“减少进度"按钮事件
case R.id.btndown:
count-=5;
if(count<=bar.getMax())
bar.setProgress(count);
current=bar.getProgress();
show="当前进度为: "+ String.valueOf(current);
Toast.makeText(getBaseContext(), show, Toast.LENGTH_LONG).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
setProgressBarIndeterminateVisibility(true);
Button btnup=(Button) findViewById(R.id.btnup);
Button btndown=(Button) findViewById(R.id.btndown);
ProgressBar progressBarHorizontal=(ProgressBar) findViewById(R.id.progressBarHorizontal);
btnup.setOnClickListener(this);

btndown.setOnClickListener(this);
}
}

//logcat提醒的错误

12-03 02:16:52.566: E/AndroidRuntime(1496): FATAL EXCEPTION: main
12-03 02:16:52.566: E/AndroidRuntime(1496): java.lang.RuntimeException: Unable to start activity ComponentInfo{carol.progressbar/carol.progressbar.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class progressBar
12-03 02:16:52.566: E/AndroidRuntime(1496): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
12-03 02:16:52.566: E/AndroidRuntime(1496): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.progressBar" on path: DexPathList[[zip file "/data/app/carol.progressbar-1.apk"],nativeLibraryDirectories=[/data/app-lib/carol.progressbar-1, /system/lib]]

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • Kelley_cfy 2014-12-04 05:16
    已采纳

    XML的progressBar是这样的ProgressBar,第一个字母大写

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • loaLakers 2014-12-04 12:07

    你看logcat提醒这里“Didn't find class "android.view.progressBar”找不到这个类,仔细看看应该是ProgressBar啊!所以找不到!
    你应该在写布局文件的时候是自己手动敲得XML代码吧!其实你可以用界面化编程啊!直接把ProgressBar拖进来就可以了,这样就不会错了啊!

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题