当前位置: 首页 > 知识库问答 >
问题:

跳过49帧!应用程序可能在主线程上做了太多的工作

张成济
2023-03-14

在我的viewpager实现中,我正在膨胀视图(而不是片段)。我的主课是拓展活动。当我尝试从我的应用程序或应用程序中滑动屏幕时,我会遇到此错误

com.example.app.CustomPagerAdapter.instantiate项目(CustomPagerAdapter.java:47)

01-04 16:44:35.5278614-8614/com.parsizabanan.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4195ee48)
01-04 16:44:35.5278614-8614/com.parsizabanan.app E/AndroidRuntime﹕ FatAL EXCEPTION: main
Process: com.parsizabanan.app, PID: 8614
android.view.InflateException: Binary XML file line #6: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInfl    ater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.parsizabanan.app.CustomPagerAdapter.instantiateItem(CustomPagerAdapter.java:47)
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:837)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1021)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
at android.view.View.measure(View.java:16574)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1406)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:697)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2421)
at android.view.View.measure(View.java:16574)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1955)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1151)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1333)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1038)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5890)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInfl ater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.parsizabanan.app.CustomPagerAdapter.instantiateItem(CustomPagerAdapter.java:47)
at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:837)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1021)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
at android.view.View.measure(View.java:16574)
at android.widget.RelativeLayout.measureChildHorizontal(Rel    ativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1406)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:697)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:16574)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2421)
at android.view.View.measure(View.java:16574)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1955)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1151)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1333)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1038)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5890)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.cre    ateFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2150)

CustomPagerAdapter:

public class CustomPagerAdapter extends PagerAdapter {

public Object instantiateItem(View collection, int position) {

    LayoutInflaterinflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLatER_SERVICE);

    int resId = 0;
    switch (position) {
        case 0: {
            resId = R.layout.lab;
            break;
        }
        case 1: {
            resId = R.layout.lab;
            break;
        }
        case 2: {
            resId = R.layout.etela;
            break;
        }
        case 3: {
            resId = R.layout.ticket;
            break;
        }
        case 4: {
            resId = R.layout.product;
            break;
        }
        case 5: {
            resId = R.layout.about;
            break;
        }

    }

    View view = inflater.inflate(resId, null);

    ((ViewPager) collection).addView(view, 0);

    return view;
}

@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
    ((ViewPager) arg0).removeView((View) arg2);
}

@Override
public boolean isViewFromObject(View arg0, Object arg1) {
    return arg0 == ((View) arg1);

}

@Override
public Parcelable saveSt    ate() {
    return null;
}

@Override
public int getCount() {
    return 6;
}

我的活动:

public class MyActivity extends Activity {
ViewPager myPager = null;
ImageButton contact = null;
ImageButton about = null;
ImageButton lab = null;
ImageButton product = null;
ImageButton ticket = null;
ImageButton etela = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    CustomPagerAdapter adapter = new CustomPagerAdapter();
    myPager = (ViewPager) findViewById(R.id.customviewpager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(5);

    myPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrolled(int i, flo    at v, int i2) {
        }

        public void onPageSelected(int i) {
        }

        public void onPageScrollStateChanged(int i) {
            Thread t1 = new Thread(new Runnable() {
                @Override
                public void run() {
                    switch (myPager.getCurrentItem()) {
                        case 0:
                            break;
                        case 1:
                            break;
                        case 2:
                            break;
                        case 3:
                            break;
                        case 4:
                            break;
                        case 5:
                            break;
                    }
                }
            });
            t1.start();
        }
    });

}

是实验室布局吗:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/lab1"/>
</LinearLayout>

共有1个答案

壤驷鸿
2023-03-14

使用大型图像可能会导致此错误。强烈建议减小图像大小,然后将其加载到ImageView。

另外,还有一种方法可以通过向清单中添加以下内容来请求android为您的应用程序提供更多内存。但不建议这样做。有关更多信息,请查看此处和此处。

<application
    ...
    android:largeHeap="true"
    ...
>

...

</application>
 类似资料:
  • 这很好,但我在日志中收到“应用程序可能做了太多工作”消息,并跳过了一系列帧。我该如何解决这个问题?

  • 我正在用这个功能为Android应用程序编码: 我成功地运行了它,但在我为Android支持设计导入了一些Nuget软件包之后,现在它抛出了这样一条消息。 我/编舞(1962):跳过了524帧!应用程序可能在其主线程上做了太多工作。 你能告诉我我做错了什么吗?

  • 我正在开发一个应用程序,它应该从网络服务中获取JSON响应,并将每个元素写入列表视图,我读到我应该使用Asyncask来获取HTTP响应,我做到了,我可以从网络服务中检索数据并在TextViews中显示它们。但是当我尝试在列表视图中显示元素时,它不会显示任何内容,并在logcat中给我以下消息: 这是我的主要代码: 我的列表适配器: 最后是搜索结果。java: 那么,我做错了什么?你对此有什么想法

  • 这发生在我将微调值保存到文件时。我已经使用线程来重新使用它的工作。但它仍然不工作...请帮助我...

  • 我查看了StackOverflow的答案,但没找到多少。所以,我这样做是为了练习,就像Hello World使用JSON一样,我从openweather API获得JSON响应。我在EditText中写下城市的名称,然后按下按钮进行搜索,并在日志中显示JSON字符串。 我该怎么做才能不收到那个消息?

  • 我在下面的代码中ping了java Android中的IP列表,但我现在的问题是运行时出现延迟,这个问题显示为“跳过602帧!应用程序可能在其主线程上做了太多工作。”有人能给我推荐一个解决方案吗?因为我是android的初学者