2012-04-28 7 views
0

以下のコードを実行すると、ログファイルに "null"が出力されます...問題は何ですか?nullプログレスバーが作成されていますか?

ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1); 
if (progressBar == null) { 
    Log.d("tag", "null"); 
} 

とxml呼び出しです:これまで

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_x="37dp" 
    android:layout_y="343dp" /> 
+0

Eclipseから「プロジェクト」>「クリーン」を実行するか、コマンドラインから「ant clean」を実行してから、もう一度アプリケーションを実行してみてください。 – CommonsWare

+0

以前にsetContentViewを呼び出しましたか? – MByD

+0

Binyaminさん、ありがとうございました。私はそれを受け入れるために答えとしてあなたのコメントを載せることができますか? – callback

答えて

2

その中にあなたのProgressBarlayoutが最初に膨張されている必要があり、あなたがかもしれませんActivity.findViewById()の代わりにView.findViewById()を使用する必要があります。私は実際に今朝、この問題を抱えていた、と私の修正はここにある:私はrootの代わりに私のActivityfindViewById()を呼び出しています

LayoutInflater infl = uI.getLayoutInflater(); 
    ViewGroup rootGroup = (ViewGroup) uI.findViewById(R.id.voltoast_root); 
    View root = infl.inflate(R.layout.volumetoast, rootGroup); 
    toast.setView(root); 
    pB = (ProgressBar) root.findViewById(R.id.progress); 

、およびrootProgressBarは一つの要素であったにLinearLayoutを含ま膨張したビューを持っています。

0

変更スタイルを:

style="@android:style/Widget.ProgressBar.Horizontal" 
関連する問題