为什么申请尽快即使没有错误警告它的推出将关闭? [英] Why Application shuts down as soon as it's launched even if there's no error caution?

查看:180
本文介绍了为什么申请尽快即使没有错误警告它的推出将关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有布局的三个XML文件,如


  1. activity_behind_left_simple.xml

  2. activity_behind_right_simple.xml

  3. activity_main.xml中

我实现textViews到 activity_behind_left_simple.xml
它显示菜单列表。它工作正常。

所以,我也做了同样的 activity_behind_right_simple.xml 了。

不过,现在的应用程序,只要它的推出将关闭:(

这是为什么?这有什么错右边?
activity_behind_left_simple.xml

 <滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    风格=@风格/ leftBehindMenuScroll>    <的LinearLayout风格=@风格/ behindMenuScrollContent
        机器人:paddingTop =25dp>        <的TextView
            风格=@风格/ behindMenuItemTitle
            机器人:文字=人物/>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT>            < jp.fureco.IconView
                机器人:ID =@ + ID / iconViewItem4
                机器人:方向=垂直
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =15dp
                机器人:TEXTSIZE =20dp/>            <的TextView
                机器人:layout_marginLeft =10dp
                风格=@风格/ behindMenuItemLabel
                机器人:文字=访客/&G​​T;        < / LinearLayout中>    < / LinearLayout中>< /滚动型>

activity_behind_right_simple.xml

 <滚动型的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    风格=@风格/ rightBehindMenuScroll>    <的LinearLayout风格=@风格/ behindMenuScrollContent
        机器人:paddingTop =25dp>        <的TextView
            风格=@风格/ behindMenuItemTitle
            机器人:文字=消息/>        <的LinearLayout
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT>            < jp.fureco.IconView
                机器人:ID =@ + ID / iconViewItem5
                机器人:方向=垂直
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_marginLeft =15dp
                机器人:TEXTSIZE =20dp/>            <的TextView
                机器人:layout_marginLeft =10dp
                风格=@风格/ behindMenuItemLabel
                机器人:文字=接收/>        < / LinearLayout中>    < / LinearLayout中>< /滚动型>

SimpleSideDrawer.java

  ....
   公共查看setLeftBehindContentView(INT leftBehindLayout){
        最后查看的内容=((LayoutInflater)的getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。)膨胀(leftBehindLayout,mLeftBehindBase)。        。的String []图标= getResources()getStringArray(R.array.icons);
        图标型控件IV4 =(图标型控件)findViewById(R.id.iconViewItem4);
        iv4.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
        iv4.setText(图标[8]);        图标型控件IV5 =(图标型控件)findViewById(R.id.iconViewItem5);
        iv5.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
        iv5.setText(图标[315]);
        mLeftPaddingRect =新的Rect(content.getPaddingLeft(),content.getPaddingTop(),content.getPaddingRight(),content.getPaddingBottom());
        mLeftBehindView =内容;
        返回的内容;
    }    ....

然后如果我删除这部分,应用程序将不会关闭了。结果
我该如何解决?

 图标型控件IV5 =(图标型控件)findViewById(R.id.iconViewItem5);
iv5.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
iv5.setText(图标[315]);

MainActivity.java

  ...
    @覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    的getSize();    mActionBar = getActionBar();
    mActionBar.hide();
    mNav =新SimpleSideDrawer(本);
    mNav.setLeftBehindContentView(R.layout.activity_behind_left_simple);
    mNav.setRightBehindContentView(R.layout.activity_behind_right_simple);
....

SimpleSideDrawer.java 我发现这一点。这有关系?

 公开查看setRightBehindContentView(INT rightBehindLayout){
    最后查看的内容=((LayoutInflater)的getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。)膨胀(rightBehindLayout,mRightBehindBase)。
    mRightPaddingRect =新的Rect(content.getPaddingLeft(),content.getPaddingTop(),content.getPaddingRight(),content.getPaddingBottom());
    mRightBehindView =内容;
    返回的内容;
}

第2部分

 公开查看setLeftBehindContentView(INT leftBehindLayout){
    最后查看的内容=((LayoutInflater)的getContext()getSystemService(Context.LAYOUT_INFLATER_SERVICE)。)膨胀(leftBehindLayout,mLeftBehindBase)。    。的String []图标= getResources()getStringArray(R.array.icons);    图标型控件IV4 =(图标型控件)findViewById(R.id.iconViewItem4);
    iv4.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
    iv4.setText(图标[25]);    图标型控件IV5 =(图标型控件)findViewById(R.id.iconViewItem5);
    iv5.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
    iv5.setText(图标[26]);    图标型控件IV6 =(图标型控件)findViewById(R.id.iconViewItem6);
    iv6.setTypeface(Typeface.createFromAsset(的getContext()getAssets(),icons.ttf)。);
    iv6.setText(图标[117]);    mLeftPaddingRect =新的Rect(content.getPaddingLeft(),content.getPaddingTop(),content.getPaddingRight(),content.getPaddingBottom());
    mLeftBehindView =内容;
    返回的内容;
}


解决方案

您需要给到充气布局的参考。试试这个与所有你的意见
setLeftBehindContentView方法中acessing:

 例如:     图标型控件IV5 =(图标型控件)content.findViewById(R.id.iconViewItem5);

请注意:我假设膨胀的布局文件中对应R.id.iconViewItems的观点在于

I have three xml files for layouts such as

  1. activity_behind_left_simple.xml
  2. activity_behind_right_simple.xml
  3. activity_main.xml

I implemented textViews to activity_behind_left_simple.xml and it shows the list of Menu. It works fine.

So I did the same on activity_behind_right_simple.xml, too.

However, now application shuts down as soon as it's launched:(

Why is that? What's wrong with right side? activity_behind_left_simple.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/leftBehindMenuScroll" >

    <LinearLayout style="@style/behindMenuScrollContent"
        android:paddingTop="25dp" >

        <TextView
            style="@style/behindMenuItemTitle"
            android:text="People" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <jp.fureco.IconView 
                android:id="@+id/iconViewItem4"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:textSize="20dp"/>

            <TextView
                android:layout_marginLeft="10dp"
                style="@style/behindMenuItemLabel"
                android:text="Visitor" />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

activity_behind_right_simple.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/rightBehindMenuScroll" >

    <LinearLayout style="@style/behindMenuScrollContent"
        android:paddingTop="25dp" >

        <TextView
            style="@style/behindMenuItemTitle"
            android:text="Messages" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <jp.fureco.IconView 
                android:id="@+id/iconViewItem5"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:textSize="20dp"/>

            <TextView
                android:layout_marginLeft="10dp"
                style="@style/behindMenuItemLabel"
                android:text="Received" />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

SimpleSideDrawer.java

    ....
   public View setLeftBehindContentView(int leftBehindLayout) {
        final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(leftBehindLayout, mLeftBehindBase);

        String[] icons = getResources().getStringArray(R.array.icons);
        IconView iv4 = (IconView) findViewById(R.id.iconViewItem4);
        iv4.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
        iv4.setText(icons[8]);

        IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
        iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
        iv5.setText(icons[315]);


        mLeftPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
        mLeftBehindView = content;
        return content;
    }        

    ....

Then if I remove this part, application won't shuts down anymore.
How can I fix?

IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
iv5.setText(icons[315]);

MainActivity.java

...
    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    getSize();

    mActionBar = getActionBar();
    mActionBar.hide();


    mNav = new SimpleSideDrawer(this);
    mNav.setLeftBehindContentView(R.layout.activity_behind_left_simple);
    mNav.setRightBehindContentView(R.layout.activity_behind_right_simple);
....

SimpleSideDrawer.java I've found this. Does this matter?

public View setRightBehindContentView(int rightBehindLayout) {
    final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(rightBehindLayout, mRightBehindBase);
    mRightPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
    mRightBehindView = content;
    return content;
}

part2

public View setLeftBehindContentView(int leftBehindLayout) {
    final View content = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(leftBehindLayout, mLeftBehindBase);

    String[] icons = getResources().getStringArray(R.array.icons);

    IconView iv4 = (IconView) findViewById(R.id.iconViewItem4);
    iv4.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv4.setText(icons[25]);

    IconView iv5 = (IconView) findViewById(R.id.iconViewItem5);
    iv5.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv5.setText(icons[26]);

    IconView iv6 = (IconView) findViewById(R.id.iconViewItem6);
    iv6.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "icons.ttf"));
    iv6.setText(icons[117]);        

    mLeftPaddingRect = new Rect(content.getPaddingLeft(), content.getPaddingTop(), content.getPaddingRight(), content.getPaddingBottom());
    mLeftBehindView = content;
    return content;
}

解决方案

You need to give a reference to the inflated layout. try this with all the views you are acessing inside setLeftBehindContentView method:

     e.g:  

     IconView iv5 = (IconView) content.findViewById(R.id.iconViewItem5);

Note: i am assuming the view corresponding to R.id.iconViewItems lies inside the inflated layout file.

这篇关于为什么申请尽快即使没有错误警告它的推出将关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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