0

サーバー上の画像で ImageView を更新しようとしています。Prime ライブラリ ( https://github.com/DHuckaby/Prime ) を使用しています。しかし、何らかの理由で、それはクラッシュします。

img リンクは次のとおりです。

http://192.168.1.36/testing/fotos/foto1.jpg

コードは次のようになります (これはフラグメントであることに注意してください。これが鍵になる可能性があります...):

public class MyFragmentA extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View myFragmentView = inflater.inflate(R.layout.fragment_a, container, false);
    try {
        String imageURL = "http://192.168.1.36/mimicit/fotos/foto1.jpg";
        Log.d("errors", "Got the link");
        RemoteImageView remoteImageView = (RemoteImageView) getView().findViewById(R.id.imageView1);
        Log.d("errors", "Done this part");
        remoteImageView.setImageURL(imageURL);
        Log.d("errors", "Done this other part");
    } catch (Exception e){
        Log.d("errors", "Wohoops. Crashed");
    }

    return myFragmentView;
}

ご覧のとおり、真ん中にログがいくつかあるので、クラッシュした場所を正確に知ることができます。

これはログの結果です:

01-04 14:15:46.363: D/errors(1030): Got the link
01-04 14:15:46.363: D/errors(1030): Wohoops. Crashed

おそらく問題は、URL がエミュレーターで機能していなかったことですが、ブラウザーを使用して正常に表示されたことです。

ここに画像の説明を入力

問題はどこにあると思いますか?

多分私はimg asyncをダウンロードする必要がありますか?それは大したことですか?つまり、そうしないとクラッシュしますか?やってみますが、非同期モードにする方法がわかりません...

ありがとうございました。

セルジ

4

1 に答える 1

2

次のコード行を置き換えます。

RemoteImageView remoteImageView = (RemoteImageView) getView().findViewById(R.id.imageView1);

と:

RemoteImageView remoteImageView = (RemoteImageView) myFragmentView .findViewById(R.id.imageView1);

エラーがスローされる理由は、onCreateView() から View を返さず、Null として取得する getView() を呼び出すことです。したがって、myFragmentView に対応する ViewById を見つけるだけです。

于 2013-01-04T14:27:45.317 に答える