简体   繁体   English

Android应用程式可在模拟器上运作,但无法在手机上运作

[英]android app working on simulator but not on phone

i have this app that i developed and it works great on the simulator with no errors what so ever. 我有我开发的这个应用程序,它可以在模拟器上很好地运行,并且没有任何错误。 but the moment i try to run the same on the phone for testing, the app crashes stating filenotfoundexception. 但是当我尝试在手机上运行相同的文件进行测试时,应用程序崩溃,并指出filenotfoundexception。 it says the file /res/drawable/divider_horizontal.9.png is missing. 表示文件/res/drawable/divider_horizo​​ntal.9.png丢失。 but actually speaking, i have never referenced that file through my code. 但实际上,我从未通过代码引用过该文件。 i believe its a system/os file that is unavailable. 我认为其系统/操作系统文件不可用。 i have a custom list view, i guess its the divider there... could somebody please suggest what is wrong here. 我有一个自定义列表视图,我猜那里是分隔线...有人可以在这里提出问题吗。 i believe this is a similar issue discussed here..but i am unable to make any sense out of it 我认为这是这里讨论的类似问题。.但是我无法理解

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

the listview.xml layout file 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>

the main xml file that calls the listview.xml 调用listview.xml的主要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>

and the code for the same is 和相同的代码是

 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;

}

The stack trace 堆栈跟踪

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

There's a problem occurring during inflation. 通货膨胀期间发生问题。 Inflating doesn't have the best error reporting/recovery, so it throws weird cryptic messages like this up when it runs into problems. 膨胀并没有最好的错误报告/恢复方法,因此当它遇到问题时,它会抛出像这样的奇怪的隐秘消息。 I'm confident the issue lies in listview.xml, and the problem is more than likely one of the xml attributes you've added to one of the elements. 我确信问题出在listview.xml中,问题很可能是您已添加到元素之一的xml属性之一。 Line #6 is I think referring to either the first or second Button element. 我认为第6行是指第一个或第二个Button元素。 When it goes to compile, it seems to give each element just one line each. 进行编译时,似乎每个元素仅分配一行。 I would start by taking out all tags that aren't immediately necessary for the program to run, like gravity and layout_weight. 我将首先取出所有不需要立即运行的标签,例如gravity和layout_weight。

Sorry I can't provide a more specific answer; 抱歉,我无法提供更具体的答案; when you run into inflation errors like this, it's a matter of probing in the dark until you find what's wrong. 当您遇到这样的通货膨胀错误时,就需要在黑暗中进行探测,直到找到问题所在。

As to why this is happening on the phone and not the emulator, more than likely there's simply an operating system difference between the two (OS version, UI being used, other changes the manufacturer has made, etc). 至于为什么这是在电话上而不是模拟器上发生的原因,很可能两者之间存在操作系统差异(操作系统版本,使用的UI,制造商进行的其他更改等)。 Testing on the emulator will give you a good idea of how the program is going to look and run on the phone, but offers no guarantee. 在模拟器上进行测试可以使您很好地了解程序在手机上的外观和运行方式,但不能保证。

Kudos on providing so much information, it makes troubleshooting a lot easier ;-) Let me know if my advice works, or if you need more information. 提供这么多信息的荣誉,使故障排除更加容易;-)让我知道我的建议是否有效,或者您是否需要更多信息。

I tried using my own resource files with a similar extension "/res/drawable/divider_horizontal.9.png" EG ".9.png" It is explained that this type of file is used for Android to know that the image has special boundaries that can adjust. 我尝试使用具有类似扩展名“ /res/drawable/divider_horizo​​ntal.9.png”例如“ EG” .9.png的自己的资源文件。据解释,这种类型的文件用于Android,以了解图像具有特殊边界可以调整的 I tried creating my own buttons using this type of file extension and I was also getting errors. 我尝试使用这种类型的文件扩展名创建自己的按钮,但同时也遇到了错误。 I replaced my files without the ".9" extension and I no longer had any issues. 我替换了没有“ .9”扩展名的文件,并且不再遇到任何问题。 When you reference the file you should never have the extension. 当您引用文件时,您永远不应具有扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用程式可在模拟器上运作,但无法在手机上运作 - android app working on simulator but not on phone Android应用程序可以在AVD上运行但不能在电话上运行吗? - Android app working on AVD but not on the phone? 手机链接在android APP中不起作用 - phone link not working in the android APP React Native应用程序可在模拟器上运行,但不能在Android设备上运行 - React Native app working on simulator but not on a android device ApI AI应用程序可以在网络模拟器上正常运行,但不能在Android手机上运行 - ApI AI app works fine on web simulator but not on Android phone Android应用无法在所有Android手机上正常运行 - Android app not working properly for all android phone 为什么要求在 android 模拟器上工作而不在 google play 商店应用程序上工作? - Why request working on android simulator but not working on google play store app? Android:在Android模拟器中请求位置更新后,应用停止运行 - Android: App stops working after requesting location updates in android simulator Monaca应用程序可在仪表板预览中运行,但不能在Android 6手机上运行 - Monaca app working in dashboard preview but not on Android 6 phone Android 应用程序在模拟器上工作但在手机上不工作(连接问题) - Android app working on emulator but not on the phone (connection issue)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM