当试图添加layoutinflater与addView获得:"跳过63帧!该应用程序可能会做它的主线程&QUOT太多的工作; [英] when trying to add layoutinflater with addView getting: "Skipped 63 frames! The application may be doing too much work on its main thread"

查看:340
本文介绍了当试图添加layoutinflater与addView获得:"跳过63帧!该应用程序可能会做它的主线程&QUOT太多的工作;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加premade布局时 onItemSelected 。没有与行的问题:

  selectLayout.addView(V);

当I C它的运行删除此$ C $。

logcat的:

  8月9日至30日:53:48.493:I /编舞(1033):63跳过帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:53:48.843:D / gralloc_goldfish(1033):无仿真模拟GPU检测。
8月9日至30日:53:48.963:I /编舞(1033):46跳过帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:54:19.894:D / dalvikvm(1033):GC_FOR_ALLOC释放82K,7%的游离2893K / 3096K,暂停135ms,170ms总
8月9日至30日:54:19.935:I / dalvikvm堆(1033):成长堆(frag的情况下),以3.543MB为635812字节分配
8月9日至30日:54:20.124:D / dalvikvm(1033):GC_FOR_ALLOC释放9K,6%免费3505K / 3720K,暂停183ms,183ms总
8月9日至30日:54:20.864:I /编舞(1033):跳过129帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:54:23.363:I /编舞(1033):91跳过帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:54:24.215:D / AndroidRuntime(1033):关闭VM
8月9日至30日:54:24.215:W / dalvikvm(1033):主题ID = 1:螺纹未捕获的异常(组= 0x41465700)退出
8月9日至30日:54:24.264:E / AndroidRuntime(1033):致命异常:主要
8月9日至30日:54:24.264:E / AndroidRuntime(1033):显示java.lang.NullPointerException
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在com.example.fitapp.Select $ 1.onItemSelected(Select.java:67)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.widget.AdapterView.access $ 200(AdapterView.java:49)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.widget.AdapterView $ SelectionNotifier.run(AdapterView.java:860)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.os.Handler.handleCallback(Handler.java:730)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.os.Handler.dispatchMessage(Handler.java:92)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.os.Looper.loop(Looper.java:137)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在android.app.ActivityThread.main(ActivityThread.java:5103)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在java.lang.reflect.Method.invokeNative(本机方法)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在java.lang.reflect.Method.invoke(Method.java:525)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
8月9日至30日:54:24.264:E / AndroidRuntime(1033):在dalvik.system.NativeStart.main(本机方法)
8月9日至30日:54:28.833:I /流程(1033):发送信号。 PID:1033 SIG:9
8月9日至30日:54:32.354:I /编舞(1054):跳过36帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:54:33.263:I /编舞(1054):跳过36帧!该应用程序可能会做它的主线程的工作太多了。
8月9日至30日:54:33.363:D / gralloc_goldfish(1054):无仿真模拟GPU检测。

另外这里是我所有的$ C $的CS。

 包com.example.fitapp;进口的java.util.HashMap;
进口的java.util.Map;进口android.app.Activity;
进口android.app.Dialog;
进口android.content.Context;
进口android.content.res.Resources;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.LinearLayout;
进口android.widget.Spinner;
进口android.widget.TextView;公共类选择扩展活动{    TextView的tvSelect,T;
    微调S选择;
    的LinearLayout selectLayout;
    的String []值;
    字符串数据;
    诠释计数= 0;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.select);        selectLayout =(的LinearLayout)findViewById(R.id.saffet);
        LayoutInflater INF =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        最后的视图V = inf.inflate(R.layout.second,NULL);        最终地图<字符串,字符串>地图=新的HashMap<字符串,字符串>();
        map.put(1,Kuvvet kazanmak istiyorsun demek?);
        map.put(2,卡斯yapmak istiyorsun demek?);
        map.put(3,O lanet olasi yaglari eritelim!);        资源R = getResources();
        值= r.getStringArray(R.array.values​​);        S选择=(微调)findViewById(R.id.sSelect);
        tvSelect =(的TextView)findViewById(R.id.tvSelect);        T =新的TextView(Select.this);        sSelect.setOnItemSelectedListener(新AdapterView.OnItemSelectedListener(){            @覆盖
            公共无效onItemSelected(适配器视图<> AV,观景,
                    INT位置,长ARG3){
                // TODO自动生成方法存根                如果(计数!= 0)
                {
                    数据=值[位置]
                    对话D =新的对话框(Select.this);
                    d.setTitle(TAMAM!);
                    t.se​​tText(map.get(数据));
                    t.se​​tPadding(5,5,5,5);
                    d.setContentView(T);
                    d.show();                    selectLayout.addView(五);
                }                数=计+ 1;            }            @覆盖
            公共无效onNothingSelected(适配器视图<>为arg0){
                // TODO自动生成方法存根            }
        });    }}

Select.xml文件:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直
    机器人:ID =@ + ID / selectLayout
    >    <的TextView
        机器人:ID =@ + ID / tvSelect
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginTop =10dp
        机器人:文字=AMACSeçiniz!
        机器人:TEXTSIZE =18sp
        机器人:layout_gravity =中心
         />    <微调
        机器人:ID =@ + ID / S选择
        机器人:layout_width =179dp
        机器人:layout_height =60dp
        机器人:layout_gravity =中心
        机器人:项=@阵列/ amaclar
        机器人:提示=@字符串/选择
         />< / LinearLayout中>


解决方案

您的LinearLayout id是

 机器人:ID =@ + ID / selectLayout

但你有这个

  selectLayout =(的LinearLayout)findViewById(R.id.saffet);

所以改为

  selectLayout =(的LinearLayout)findViewById(R.id.selectLayout);


  

应用程序可能会做太多的工作在其主线程。


您的主线程是UI线程。由于commonsware建议使用traceview。你有做一些密集计算怎么我没有看到大量的运算在 Select.java 等活动。如果是这样使用线程的AsyncTask

I'm trying to add premade layout when onItemSelected. There is problem with the line:

selectLayout.addView(v);

When I remove this code It's running.

Logcat:

09-30 08:53:48.493: I/Choreographer(1033): Skipped 63 frames!  The application may be doing too much work on its main thread.
09-30 08:53:48.843: D/gralloc_goldfish(1033): Emulator without GPU emulation detected.
09-30 08:53:48.963: I/Choreographer(1033): Skipped 46 frames!  The application may be doing too much work on its main thread.
09-30 08:54:19.894: D/dalvikvm(1033): GC_FOR_ALLOC freed 82K, 7% free 2893K/3096K, paused 135ms, total 170ms
09-30 08:54:19.935: I/dalvikvm-heap(1033): Grow heap (frag case) to 3.543MB for 635812-byte allocation
09-30 08:54:20.124: D/dalvikvm(1033): GC_FOR_ALLOC freed 9K, 6% free 3505K/3720K, paused 183ms, total 183ms
09-30 08:54:20.864: I/Choreographer(1033): Skipped 129 frames!  The application may be doing too much work on its main thread.
09-30 08:54:23.363: I/Choreographer(1033): Skipped 91 frames!  The application may be doing too much work on its main thread.
09-30 08:54:24.215: D/AndroidRuntime(1033): Shutting down VM
09-30 08:54:24.215: W/dalvikvm(1033): threadid=1: thread exiting with uncaught exception (group=0x41465700)
09-30 08:54:24.264: E/AndroidRuntime(1033): FATAL EXCEPTION: main
09-30 08:54:24.264: E/AndroidRuntime(1033): java.lang.NullPointerException
09-30 08:54:24.264: E/AndroidRuntime(1033):     at com.example.fitapp.Select$1.onItemSelected(Select.java:67)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:892)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.widget.AdapterView.access$200(AdapterView.java:49)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:860)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.os.Handler.handleCallback(Handler.java:730)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.os.Looper.loop(Looper.java:137)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at android.app.ActivityThread.main(ActivityThread.java:5103)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invokeNative(Native Method)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at java.lang.reflect.Method.invoke(Method.java:525)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-30 08:54:24.264: E/AndroidRuntime(1033):     at dalvik.system.NativeStart.main(Native Method)
09-30 08:54:28.833: I/Process(1033): Sending signal. PID: 1033 SIG: 9
09-30 08:54:32.354: I/Choreographer(1054): Skipped 36 frames!  The application may be doing too much work on its main thread.
09-30 08:54:33.263: I/Choreographer(1054): Skipped 36 frames!  The application may be doing too much work on its main thread.
09-30 08:54:33.363: D/gralloc_goldfish(1054): Emulator without GPU emulation detected.

Also here is the all of my codes.

package com.example.fitapp;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

public class Select extends Activity{

    TextView tvSelect, t;
    Spinner sSelect;
    LinearLayout selectLayout;
    String[] values;
    String data;
    int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select);

        selectLayout = (LinearLayout) findViewById(R.id.saffet);
        LayoutInflater inf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View v = inf.inflate(R.layout.second, null);

        final Map<String,String> map = new HashMap<String,String>();
        map.put("1", "Kuvvet kazanmak istiyorsun demek?");
        map.put("2", "Kas yapmak istiyorsun demek?");
        map.put("3", "O lanet olasi yaglari eritelim!");

        Resources r = getResources();
        values = r.getStringArray(R.array.values);

        sSelect = (Spinner) findViewById(R.id.sSelect);
        tvSelect = (TextView) findViewById(R.id.tvSelect);

        t = new TextView(Select.this);

        sSelect.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> av, View view,
                    int position, long arg3) {
                // TODO Auto-generated method stub

                if(count!=0)
                {
                    data = values[position];
                    Dialog d = new Dialog(Select.this);
                    d.setTitle("Tamam!");
                    t.setText(map.get(data));
                    t.setPadding(5, 5, 5, 5);
                    d.setContentView(t);
                    d.show();

                    selectLayout.addView(v);
                }

                count = count + 1;

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });

    }

}

Select.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:id="@+id/selectLayout"
    >

    <TextView
        android:id="@+id/tvSelect"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Amaç Seçiniz!"
        android:textSize="18sp"
        android:layout_gravity="center"
         />

    <Spinner
        android:id="@+id/sSelect"
        android:layout_width="179dp"
        android:layout_height="60dp"
        android:layout_gravity="center"
        android:entries="@array/amaclar"
        android:prompt="@string/select"
         />

</LinearLayout>

解决方案

Your LinearLayout id is

 android:id="@+id/selectLayout"

But you have this

selectLayout = (LinearLayout) findViewById(R.id.saffet);

So change to

selectLayout = (LinearLayout) findViewById(R.id.selectLayout);

The application may be doing too much work on its main thread.

Your main thread is the ui thread. As commonsware suggested use traceview. Do you have other activities that do some intensive computation coz i don't see a lot of computation in Select.java . If so use a thread or asynctask.

这篇关于当试图添加layoutinflater与addView获得:&QUOT;跳过63帧!该应用程序可能会做它的主线程&QUOT太多的工作;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆