0

私は StackOverflow で多くのことを検索しました。いくつかのコメントでは、この問題を解決するためにプロジェクトをクリーンアップすることをお勧めします。問題は Adapter 内の asynctask クラスで発生するため、次のようになります。

  1. Eclipse、ディレクトリ(gen / bin)からプロジェクトを削除し、再度インポートしました
  2. インポートを削除し、プロジェクトをクリーンアップし、ctrl+O (再度インポートするため)、プロジェクトを再度コンパイルしました

動作しませんでした!

このエラーが発生するコードの一部:

protected void onPreExecute() {

        ImageView img = (ImageView) mView.findViewById(R.id.grid_action_button);

        if(img == null){
            Log.d(TAG, "img null");
        }else{
            Log.d(TAG, "img not null");
        }

        ProgressBar pBar = (ProgressBar) mView.findViewById(R.id.grid_progress_bar);

        if(pBar == null){
            Log.d(TAG, "pBar null");
        }else{
            Log.d(TAG, "pBar not null");
        }

    }

最も興味深いのは、imageview は正常に動作しますが、pBar変数の戻り値が null であることです。

Logcat の結果:

04-02 15:46:00.734: D/Adapter(10842): img not null
04-02 15:46:00.734: D/Adapter(10842): pBar null

griview レイアウト (mobile.xml) への私のカスタム アダプター:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="30dp" >

    <ImageView
        android:id="@+id/grid_item_image"
        android:layout_width="140dp"
        android:layout_height="186dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/ic_launcher" >
    </ImageView>

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:orientation="vertical"
        >
        <!-- I have some TextViews here -->

    <ImageView
            android:id="@+id/grid_action_button"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginTop="10dp"
            android:src="@drawable/btn_download"
            android:clickable="true" >
            </ImageView>

    <ProgressBar             
        android:id="@+id/grid_progress_bar"
        android:layout_width="100dp"
        android:layout_height="10dp"
        style="style/Widget.ProgressBar.Horizontal"
    />

</LinearLayout>
</LinearLayout>

setContentViewMain クラスで呼び出されます。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    gridView = (GridView) findViewById(R.id.gridview);
}

getview()の内部アダプタークラス:

public View getView(int position, View convertView, ViewGroup parent) {

    View gridView = convertView;

    if (gridView == null) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // get layout from mobile.xml
        gridView = inflater.inflate(R.layout.mobile, null);

            ... more ...

ありがとう

4

1 に答える 1