Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我单击页面时,应用程序强制关闭_Java_Android_Xml - Fatal编程技术网

Java 当我单击页面时,应用程序强制关闭

Java 当我单击页面时,应用程序强制关闭,java,android,xml,Java,Android,Xml,我设计了一个android应用程序的个人资料页面。但是,当我单击此页面时,它将强制关闭。如何防止撞车 res/layout/fragment\u profile\u vp.xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://sche

我设计了一个android应用程序的个人资料页面。但是,当我单击此页面时,它将强制关闭。如何防止撞车

res/layout/fragment\u profile\u vp.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.ray.myoufd.Profile_vp">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <ImageView
            android:id="@+id/header_cover_image"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:scaleType="centerCrop"
            android:src="@drawable/profilebg" />

        <ImageButton
            android:id="@+id/user_profile_photo"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_below="@+id/header_cover_image"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-60dp"
            android:elevation="5dp"
            android:scaleType="centerCrop"
            android:src="@drawable/defaultpropic" />

        <RelativeLayout
            android:id="@+id/profile_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header_cover_image"
            android:background="@color/grey"
            android:elevation="4dp"
            android:paddingBottom="24dp">


            <TextView
                android:id="@+id/user_profile_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="76dp"
                android:text="Name"
                android:textColor="#fff"
                android:textSize="24sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/user_profile_short_bio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/user_profile_name"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="12dp"
                android:text="profile short bio"
                android:textColor="#fff"
                android:textSize="14sp" />
        </RelativeLayout>


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:layout_marginTop="0dp"
            android:orientation="horizontal"
            android:id="@+id/linearLayout1"
            android:background="@color/white">

            <TextView
                android:layout_height="wrap_content"
                android:text="Name:"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:layout_margin="5dp"
                android:textColor="@color/green"/>

            <EditText
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@color/black"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:layout_marginTop="43dp"
            android:orientation="horizontal"
            android:id="@+id/linearLayout2"
            android:background="@color/white">

            <TextView
                android:layout_height="wrap_content"
                android:text="Gender:"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:layout_margin="5dp"
                android:textColor="@color/green"/>

            <EditText
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@color/black"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:layout_marginTop="86dp"
            android:orientation="horizontal"
            android:id="@+id/linearLayout3"
            android:background="@color/white" >

            <TextView
                android:layout_height="wrap_content"
                android:text="Email:"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:layout_margin="5dp"
                android:textColor="@color/green"/>

            <EditText
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@color/black"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:layout_marginTop="129dp"
            android:orientation="horizontal"
            android:id="@+id/linearLayout4"
            android:background="@color/white">

            <TextView
                android:layout_height="wrap_content"
                android:text="Date o birth:"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:layout_margin="5dp"
                android:textColor="@color/green"/>

            <EditText
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@color/black"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_layout"
            android:layout_marginTop="172dp"
            android:orientation="vertical"
            android:id="@+id/linearLayout5"
            android:background="@color/white">

            <TextView
                android:layout_height="wrap_content"
                android:text="Message to friend"
                android:layout_width="wrap_content"
                android:textSize="18sp"
                android:layout_margin="5dp"
                android:textColor="@color/green"/>

            <EditText
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@color/black"/>
        </LinearLayout>

            <Button
                android:text="Logout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/button"
                android:layout_marginStart="115dp"
                android:layout_marginLeft="115dp"
                android:background="@color/green"
                android:layout_marginTop="605dp" />

            <Button
                android:text="Save"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/button2"
                android:layout_marginTop="605dp"
                android:layout_marginLeft="210dp"
                android:layout_marginStart="210dp"
                android:background="@color/green"
            />
    </RelativeLayout>
</ScrollView>
</FrameLayout>
java/com.example.ray.myoufd/MainPage.java

package com.example.ray.myoufd;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.gigamole.navigationtabbar.ntb.NavigationTabBar;

import java.util.ArrayList;
import java.util.List;

public class MainPage extends AppCompatActivity {

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

    private void initUI() {
        final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);

        final String[] colors = getResources().getStringArray(R.array.default_preview);
        final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
        final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.home),
                        Color.parseColor(colors[0]))
                        .title("Home")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.search),
                        Color.parseColor(colors[1]))
                        .title("Search")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.friend),
                        Color.parseColor(colors[2])).
                        badgeTitle("123")
                        .title("Friend")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.personal),
                        Color.parseColor(colors[3]))
                        .title("Profile")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.chat),
                        Color.parseColor(colors[4]))
                        .title("Discuss")
                        .build()
        );

        navigationTabBar.setModels(models);


        Search_vp search_Vp = new Search_vp();
        Home_vp home_vp = new Home_vp();
        Friend_vp friend_vp =new Friend_vp();
        Discuss_vp discuss_vp = new Discuss_vp();
        Profile_vp profile_vp = new Profile_vp();
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(home_vp);
        fragmentList.add(search_Vp);
        fragmentList.add(friend_vp);
        fragmentList.add(profile_vp);
        fragmentList.add(discuss_vp);
        FragmentPageAdapter fragmentPageAdapter =new FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
        viewPager.setAdapter(fragmentPageAdapter);
        navigationTabBar.setViewPager(viewPager, 0);


        navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(final int position) {
                navigationTabBar.getModels().get(position).hideBadge();
            }

            @Override
            public void onPageScrollStateChanged(final int state) {

            }
        });


        navigationTabBar.postDelayed(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
                    final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
                    navigationTabBar.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            model.showBadge();
                        }
                    }, i * 100);
                }
            }
        }, 500);
    }

}
package com.example.ray.myoufd;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.support.v4.view.ViewPager;
导入android.support.v7.app.AppActivity;
导入com.gigamole.navigationtabbar.ntb.navigationtabbar;
导入java.util.ArrayList;
导入java.util.List;
公共类主页扩展了AppCompatActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u主页);
initUI();
}
私有void initUI(){
final ViewPager ViewPager=(ViewPager)findViewById(R.id.vp\u horizontal\u ntb);
最终字符串[]colors=getResources().getStringArray(R.array.default\u预览);
最终导航选项卡栏导航选项卡栏=(导航选项卡栏)findViewById(R.id.ntb_水平);
最终ArrayList模型=新ArrayList();
models.add(
新建NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.home),
parseColor(颜色[0]))
.头衔(“家”)
.build()
);
models.add(
新建NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.search),
parseColor(颜色[1]))
.标题(“搜索”)
.build()
);
models.add(
新建NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.friend),
parseColor(colors[2])。
徽章名称(“123”)
.头衔(“朋友”)
.build()
);
models.add(
新建NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.personal),
parseColor(颜色[3]))
.标题(“简介”)
.build()
);
models.add(
新建NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.chat),
parseColor(颜色[4]))
.标题(“讨论”)
.build()
);
navigationTabBar.setModels(模型);
Search_vp Search_vp=新搜索_vp();
Home_vp Home_vp=新Home_vp();
Friend_vp Friend_vp=新朋友_vp();
讨论讨论=新讨论;
Profile_vp Profile_vp=新的Profile_vp();
List fragmentList=新建ArrayList();
碎片列表。添加(主视图);
碎片列表。添加(搜索\u Vp);
碎片列表。添加(朋友\副总裁);
碎片列表。添加(配置文件\u vp);
碎片列表。添加(讨论vp);
FragmentPageAdapter FragmentPageAdapter=新的FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
viewPager.setAdapter(fragmentPageAdapter);
navigationTabBar.setViewPager(viewPager,0);
navigationTabBar.setOnPageChangeListener(新的ViewPager.OnPageChangeListener(){
@凌驾
已滚动页面上的公共无效(最终整型位置、最终浮点位置偏移、最终整型位置偏移像素){
}
@凌驾
已选择页面上的公共无效(最终整型位置){
navigationTabBar.getModels().get(位置).HidebEdge();
}
@凌驾
公共无效onPageScrollStateChanged(最终整型状态){
}
});
navigationTabBar.postDelayed(新的Runnable(){
@凌驾
公开募捐{
对于(int i=0;i
您看到错误消息了吗?没有错误消息。我可以在手机上打开。但当我切换到个人资料页面时,它将强制关闭。您的日志猫中有一条错误消息。从这里发布堆栈跟踪。资源:请帮助
package com.example.ray.myoufd;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.gigamole.navigationtabbar.ntb.NavigationTabBar;

import java.util.ArrayList;
import java.util.List;

public class MainPage extends AppCompatActivity {

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

    private void initUI() {
        final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);

        final String[] colors = getResources().getStringArray(R.array.default_preview);
        final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
        final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.home),
                        Color.parseColor(colors[0]))
                        .title("Home")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.search),
                        Color.parseColor(colors[1]))
                        .title("Search")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.friend),
                        Color.parseColor(colors[2])).
                        badgeTitle("123")
                        .title("Friend")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.personal),
                        Color.parseColor(colors[3]))
                        .title("Profile")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.chat),
                        Color.parseColor(colors[4]))
                        .title("Discuss")
                        .build()
        );

        navigationTabBar.setModels(models);


        Search_vp search_Vp = new Search_vp();
        Home_vp home_vp = new Home_vp();
        Friend_vp friend_vp =new Friend_vp();
        Discuss_vp discuss_vp = new Discuss_vp();
        Profile_vp profile_vp = new Profile_vp();
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(home_vp);
        fragmentList.add(search_Vp);
        fragmentList.add(friend_vp);
        fragmentList.add(profile_vp);
        fragmentList.add(discuss_vp);
        FragmentPageAdapter fragmentPageAdapter =new FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
        viewPager.setAdapter(fragmentPageAdapter);
        navigationTabBar.setViewPager(viewPager, 0);


        navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(final int position) {
                navigationTabBar.getModels().get(position).hideBadge();
            }

            @Override
            public void onPageScrollStateChanged(final int state) {

            }
        });


        navigationTabBar.postDelayed(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
                    final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
                    navigationTabBar.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            model.showBadge();
                        }
                    }, i * 100);
                }
            }
        }, 500);
    }

}