程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> progress bar-【android新手】進度條progressBar無法運行問題

progress bar-【android新手】進度條progressBar無法運行問題

編輯:編程綜合問答
【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]]

最佳回答:


XML的progressBar是這樣的ProgressBar,第一個字母大寫

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved