2010-12-14 11 views
0

私はこのアプリを開発しましたが、これはエラーなしでシミュレータでうまく動作します。しかし、私はテストのために電話で同じを実行しようとする瞬間、アプリケーションはfilenotfoundeceptionを述べてクラッシュする。 /res/drawable/divider_horizo​​ntal.9.pngファイルが存在しないことを示します。実際に言えば、自分のコードでそのファイルを参照したことはありません。 私はそのシステム/ osファイルが利用できないと信じています。私はカスタムリストビューを持っています、私はそこの仕切りを推測します... 誰かがここで間違っていることをお勧めします。私はこれは私が外のいずれかの意味を理解することができませんhere..but議論し、同様の問題であると信じて、それアンドロイドアプリは電話ではなくシミュレータで動作します

http://code.google.com/p/transdroid/issues/detail?id=14

listview.xmlレイアウトファイル

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" android:gravity="left|center" 
    android:layout_width="wrap_content" android:paddingBottom="5px" 
    android:paddingTop="5px" android:paddingLeft="5px" > 
    <ImageView android:id="@+id/linkImage" android:layout_width="wrap_content" 
     android:layout_height="fill_parent" android:layout_marginRight="6dip" 
     android:src="@drawable/icon" /> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="0dip" android:layout_weight="1" 
     android:layout_height="fill_parent"> 
     <TextView android:id="@+id/firstLineView" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:gravity="center" android:textColor="#FFFF00" android:text="first line title"></TextView> 

     <TextView android:id="@+id/secondLineView" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:text="second line title" android:layout_marginLeft="10px" android:gravity="center" 
      android:textColor="#0099CC"></TextView> 

    </LinearLayout> 
</LinearLayout> 

呼び出すメインのxmlファイルをlistview.xml

<?xml version="1.0" encoding="UTF-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 

    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <LinearLayout android:orientation="horizontal" 
      android:layout_width="fill_parent" android:layout_height="40px"> 
      <Button android:id="@+id/todayButton" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:text="Today" 
       android:textSize="12sp" android:gravity="center" 
       android:layout_weight="1" /> 
      <Button android:id="@+id/tomorrowButton" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:text="Tomorrow" 
       android:textSize="12sp" android:layout_weight="1" /> 

      <Button android:id="@+id/WeekButton" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:text="Future" 
       android:textSize="12sp" android:layout_weight="1" /> 


     </LinearLayout> 
     <LinearLayout android:id="@+id/listLayout" 
      android:orientation="vertical" android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <ListView android:id="@+id/ListView01" android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
      <TextView android:id="@id/android:empty" 
       android:layout_width="fill_parent" android:layout_height="fill_parent" 
       android:text="No Results" /> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 

と同一のコードが

あります
private class EfficientAdapter extends BaseAdapter{ 
     private LayoutInflater mInflater; 

     private String eventTitleArray[]; 


private String eventDateArray[]; 
    private String eventImageLinkArray[]; 


    public EfficientAdapter(Context context,String[] eventTitleArray,String[] eventDateArray, String[] eventImageLinkArray){ 
     mInflater = LayoutInflater.from(context); 

     this.eventDateArray=eventDateArray; 
     this.eventTitleArray=eventTitleArray; 
     this.eventImageLinkArray =eventImageLinkArray; 

    } 
    public int getCount(){ 
     //return XmlParser.todayEvents.size()-1; 
     return this.eventDateArray.length; 
    } 
    public Object getItem(int position){ 
     return position; 
    } 
    public long getItemId(int position){ 
     return position; 
    } 
    public View getView(int position, View convertView, ViewGroup parent){ 
     ViewHolder holder; 
     if(convertView == null){ 
      convertView = mInflater.inflate(R.layout.listview,null); 
     holder = new ViewHolder(); 
     holder.firstLine = (TextView) convertView.findViewById(R.id.firstLineView); 
     holder.secondLine = (TextView) convertView.findViewById(R.id.secondLineView); 
     holder.imageView = (ImageView) convertView.findViewById(R.id.linkImage); 
     //holder.checkbox = (CheckBox) convertView.findViewById(R.id.star); 
     holder.firstLine.setFocusable(false); 
     holder.secondLine.setFocusable(false); 
     holder.imageView.setFocusable(false); 
     //holder.checkbox.setFocusable(false); 
     convertView.setTag(holder); 
    }else{ 
     holder = (ViewHolder) convertView.getTag(); 
    } 
    Log.i(tag, "Creating the list"); 
    holder.firstLine.setText(this.eventTitleArray[position]); 
    holder.secondLine.setText(this.eventDateArray[position]); 

    Bitmap bitmap; 
    try { 
     bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://edu/images/heinz7.jpg").getContent()); 
    } catch (MalformedURLException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } catch (Exception e1) { 
     // TODO Auto-generated catch block 
     bitmap = BitmapFactory.decodeFile("assets/heinz7.jpg");//decodeFile(getResources().getAssets().open("icon.png")); 
     e1.printStackTrace(); 
    } 
    try { 
     try{ 
      bitmap = BitmapFactory.decodeStream((InputStream)new URL(this.eventImageLinkArray[position]).getContent());} 
     catch(Exception e){ 
      bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://eventur.sis.pitt.edu/images/heinz7.jpg").getContent()); 
     } 

     int width = 0; 
     int height =0; 
     int newWidth = 50; 
     int newHeight = 40; 

     try{ 
      width = bitmap.getWidth(); 
      height = bitmap.getHeight(); 
     } 
     catch(Exception e){ 
      width = 50; 
      height = 40; 
     } 
     float scaleWidth = ((float)newWidth)/width; 
     float scaleHeight = ((float)newHeight)/height; 
     Matrix mat = new Matrix(); 
     mat.postScale(scaleWidth, scaleHeight); 

     try{ 
      Bitmap newBitmap = Bitmap.createBitmap(bitmap,0,0,width,height,mat,true); 
      BitmapDrawable bmd = new BitmapDrawable(newBitmap); 
      holder.imageView.setImageDrawable(bmd); 
      holder.imageView.setScaleType(ScaleType.CENTER); 
     } 
     catch(Exception e){ 

     } 

    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 



    return convertView; 
} 
class ViewHolder{ 
    TextView firstLine; 
    TextView secondLine; 
    ImageView imageView; 
    //CheckBox checkbox; 

} 

スタックトレース

12-12 22:55:25.022: ERROR/AndroidRuntime(11069): Uncaught handler: thread main exiting due to uncaught exception 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069): android.view.InflateException: Binary XML file line #6: Error inflating class java.lang.reflect.Constructor 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.createView(LayoutInflater.java:512) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:617) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at com.eventur.MainActivity$EfficientAdapter.getView(MainActivity.java:566) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.AbsListView.obtainView(AbsListView.java:1274) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ListView.makeAndAddView(ListView.java:1661) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ListView.fillDown(ListView.java:610) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ListView.fillFromTop(ListView.java:673) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ListView.layoutChildren(ListView.java:1519) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.AbsListView.onLayout(AbsListView.java:1113) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.View.layout(View.java:6156) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.ViewRoot.performTraversals(ViewRoot.java:950) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1529) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.os.Looper.loop(Looper.java:123) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.app.ActivityThread.main(ActivityThread.java:3977) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at java.lang.reflect.Method.invoke(Method.java:521) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at dalvik.system.NativeStart.main(Native Method) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069): Caused by: java.lang.reflect.InvocationTargetException 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ImageView.<init>(ImageView.java:128) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at java.lang.reflect.Constructor.constructNative(Native Method) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.view.LayoutInflater.createView(LayoutInflater.java:499) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  ... 42 more 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/divider_horizontal_dark.9.png from drawable resource ID #0x7f020001 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.content.res.Resources.loadDrawable(Resources.java:1643) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.content.res.TypedArray.getDrawable(TypedArray.java:548) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.widget.ImageView.<init>(ImageView.java:138) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  ... 46 more 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069): Caused by: java.io.FileNotFoundException: res/drawable/divider_horizontal_dark.9.png 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.content.res.AssetManager.openNonAssetNative(Native Method) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.content.res.AssetManager.openNonAsset(AssetManager.java:417) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  at android.content.res.Resources.loadDrawable(Resources.java:1636) 
12-12 22:55:25.212: ERROR/AndroidRuntime(11069):  ... 48 more 
+0

リストビューのgetView()メソッドでビットマップイメージを真剣にダウンロードしていますか?それは確かに正しくありません。たとえそれがasynctaskにあったとしても、それはまだ普通には最良のアイデアではありません。 – Falmarri

+0

どのUIテーマを使用していますか(Android標準、HTCの意味...カスタム?)、これをテストしている電話はありますか?おそらく、そのリソースは現在のUIテーマの下に存在しないでしょう。 –

+0

エミュレータと電話で使用しているアンドロイドのバージョンは何ですか?あなたのsdk設定は何に設定されていますか? –

答えて

1

インフレ時に発生する問題があります。膨らみは最高のエラー報告/回復を持たないので、問題に遭遇すると、このような不思議な秘密のメッセージがスローされます。問題がlistview.xmlにあると確信しています。問題は、要素の1つに追加したxml属性の可能性が高いことです。 6行目は、最初のButton要素か2番目のButton要素のどちらかを指していると思います。コンパイルすると、各要素にそれぞれ1行しか与えられないようです。重力やレイアウトのようなプログラムを実行するために直ちに必要でないすべてのタグを取り出すことから始めます。

申し訳ありませんもっと具体的な回答はありません。このようなインフレ・エラーに遭遇すると、何が間違っているかを見つけるまで、暗闇の中でプロービングすることになります。

エミュレータではなく電話機でこの現象が発生している理由は、オペレーティングシステムの違い(OSのバージョン、使用されているUI、製造元の変更など)が原因である可能性があります。エミュレータをテストすることで、プログラムが電話でどのように表示され、実行されるかを知ることができますが、保証はありません。

多くの情報を提供してくれたことで、トラブルシューティングがもっと簡単になりました;-)私のアドバイスがうまくいくかどうか、さらに詳しい情報が必要な場合は教えてください。

+0

@ attraudes ...詳細な返信をお願いします。私は確かにそれほど重要でないタグを取り除くことによってこれをテストします..それは仕事を望むでしょう.. –

+0

あなたはそれを得ました;-)幸運! – atraudes

+0

@ astraudes ..私はあまり重要でないタグを削除しようとしましたが、アプリはまだ携帯電話にロードされません。また、エミュレータでは実際に持っているはずのデザインが失われています...他のアンドロイドベースの携帯電話は動作するのだろうか? –

0

私は、同様の拡張子 "/res/drawable/divider_horizo​​ntal.9.png" E.G.を持つ自分のリソースファイルを使用しようとしました。 ".9.png"このタイプのファイルは、画像に調整できる特別な境界があることをAndroidが認識するために使用されると説明されています。このタイプのファイル拡張子を使用して独自のボタンを作成しようとしましたが、エラーが発生していました。 ".9"拡張子を付けずにファイルを置き換えたので、私はもはや問題はありませんでした。ファイルを参照するときには、拡張子を持つべきではありません。

関連する問題