Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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_Json_Crash - Fatal编程技术网

Java 我目前正在为最后一年开发一个应用程序。没有出现错误,但当我选择我的搜索屏幕时,应用程序崩溃

Java 我目前正在为最后一年开发一个应用程序。没有出现错误,但当我选择我的搜索屏幕时,应用程序崩溃,java,android,json,crash,Java,Android,Json,Crash,我开始为我最后一年的项目开发一个应用程序。我创建了所有没有问题的导航抽屉,当我运行程序时,它们工作得很好。当我添加了一个搜索页面,该页面将链接到我添加的MapsActivity。没有出现任何错误,但应用程序将正常运行,但当我单击导航抽屉访问搜索页面和mapsActivity页面时,应用程序崩溃。你知道问题是什么吗 下面是我的搜索屏幕的代码 package com.example.mcdai.derrytourism; import android.content.Context; import

我开始为我最后一年的项目开发一个应用程序。我创建了所有没有问题的导航抽屉,当我运行程序时,它们工作得很好。当我添加了一个搜索页面,该页面将链接到我添加的MapsActivity。没有出现任何错误,但应用程序将正常运行,但当我单击导航抽屉访问搜索页面和mapsActivity页面时,应用程序崩溃。你知道问题是什么吗

下面是我的搜索屏幕的代码

package com.example.mcdai.derrytourism;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;


public class SearchScreen extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    Spinner restaurantSpinner, accommidationSpinner;
    ArrayAdapter<CharSequence> adapter;
    Button btnSearch;
    TextView buttonLogout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_screen);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        final EditText freeTextEntry = (EditText)findViewById(R.id.editFreeTextSearch);
        //final EditText editMinDestination = (EditText)findViewById(R.id.editMinDestination);
        final EditText editMaxDestination = (EditText)findViewById(R.id.editMaxDestination);
        final EditText editMinPrice = (EditText)findViewById(R.id.editMinPrice);
        final EditText editMaxPrice = (EditText)findViewById(R.id.editMaxPrice);
        final Spinner spinnerRestautantType = (Spinner)findViewById(R.id.spinnerRestaurantType);
        final Spinner spinnerAccommidationType = (Spinner)findViewById(R.id. spinnerAccommidationType);
        buttonLogout = (TextView)findViewById(R.id.buttonLogout);

        editMinPrice.setEnabled(false);
        editMaxPrice.setEnabled(false);
        spinnerRestautantType.setEnabled(false);
        spinnerAccommidationType.setEnabled(false);

        //restaurant drop down menu
        restaurantSpinner = (Spinner)findViewById(R.id.spinnerRestaurantType);
        adapter = ArrayAdapter.createFromResource(this,R.array.restaurant_type, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        restaurantSpinner.setAdapter(adapter);
        restaurantSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                TextView defaultPleaseSelect = (TextView) view;
                if(position == 0)
                {
                    // Set hint size and colour
                    defaultPleaseSelect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                    defaultPleaseSelect.setTextColor(Color.GRAY);
                }
                else
                {
                    // Set dropdown selection and display an onscreen message
                    Toast.makeText(getBaseContext(),parent.getItemAtPosition(position)+" selected", Toast.LENGTH_LONG).show();
                }
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });


        //Accommidation drop down menu
        accommidationSpinner = (Spinner)findViewById(R.id.spinnerAccommidationType );
        adapter = ArrayAdapter.createFromResource(this,R.array.accommidation, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        accommidationSpinner.setAdapter(adapter);
        accommidationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                TextView defaultPleaseSelect = (TextView) view;
                if(position == 0)
                {
                    // Set hint size and colour
                    defaultPleaseSelect.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
                    defaultPleaseSelect.setTextColor(Color.GRAY);
                }
                else
                {
                    // Set dropdown selection and display an onscreen message
                    Toast.makeText(getBaseContext(),parent.getItemAtPosition(position)+" selected", Toast.LENGTH_LONG).show();
                }
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });



        btnSearch = (Button)findViewById(R.id.btnSearch);
        btnSearch.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {

                Intent intentMapsActivity = new Intent(SearchScreen.this, MapsActivity.class);


                //code to get min desitance for destination
                //String minDestination = editMinDestination.getText().toString().trim();
                //code to get max distance for destination
                if(editMaxDestination.getText().toString().equals(""))
                {
                    Toast.makeText(SearchScreen.this, "Please Populate Distance Field", Toast.LENGTH_LONG).show();
                }
                else
                {
                    Double maxDestination = Double.parseDouble(editMaxDestination.getText().toString());
                    //code to get from editTextFreeSearch
                    String freeTextSearchParam = freeTextEntry.getText().toString();
                    //code to get restaurant type spinner
                    String restaurantTypeSpinner = spinnerRestautantType.getSelectedItem().toString();
                    //code to get accommidation type spinner
                    String accommidationSpinner = spinnerAccommidationType .getSelectedItem().toString();

                    if(freeTextSearchParam.equals("") && restaurantTypeSpinner.equals("Select") && accommidationSpinner.equals("Select"))
                    {
                        Toast.makeText(SearchScreen.this, "Please Populate Free Text, Price or Restaurant Type", Toast.LENGTH_LONG).show();
                    }
                    else
                    {
                        freeTextSearchParam = freeTextSearchParam.replaceAll("\\s", "\\+");
                        intentMapsActivity.putExtra("freeTextSearch", freeTextSearchParam);
                        intentMapsActivity.putExtra("maxDestination", maxDestination);
                        restaurantTypeSpinner = restaurantTypeSpinner.replaceAll("\\s", "\\+");
                        intentMapsActivity.putExtra("restaurantType", restaurantTypeSpinner);
                        accommidationSpinner = accommidationSpinner.replaceAll("\\s", "\\+");
                        intentMapsActivity.putExtra("accommidation", accommidationSpinner);
                        startActivity(intentMapsActivity);
                    }
                }
            }

        });

        buttonLogout = (TextView)findViewById(R.id.buttonLogout);
        buttonLogout.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                Intent intent = new Intent(getApplicationContext(), SearchScreen.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }

        });


    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if ( v instanceof EditText) {
                Rect outRect = new Rect();
                v.getGlobalVisibleRect(outRect);
                if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
                    v.clearFocus();
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
        }
        return super.dispatchTouchEvent( event );
    }

    public void onRadioButtonClicked(View view)
    {
        //EditText editMinDestination = (EditText)findViewById(R.id.editMinDestination);
        EditText editMaxDestination = (EditText)findViewById(R.id.editMaxDestination);
        EditText editMinPrice = (EditText)findViewById(R.id.editMinPrice);
        EditText editMaxPrice = (EditText)findViewById(R.id.editMaxPrice);
        Spinner spinnerRestautantType = (Spinner)findViewById(R.id.spinnerRestaurantType);
        Spinner spinnerAccommidationType  = (Spinner)findViewById(R.id.spinnerAccommidationType );
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();
        boolean unchecked = !((RadioButton) view).isChecked();

        switch(view.getId())
        {
            case R.id.radioPrice:
                if (checked)
                {
                    editMinPrice.setEnabled(true);
                    editMaxPrice.setEnabled(true);
                }break;
            case R.id.radioRestuarantType:
                if (checked)
                {
                    spinnerRestautantType.setEnabled(true);
                } break;
            case R.id.radioAccommidationType:
                if (checked)
                {
                    spinnerAccommidationType.setEnabled(true);
                }break;
        }
    }
    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.search_screen, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.nav_MainActivity) {
            Intent intentMainActivity = new Intent(SearchScreen.this, MainActivity.class);
            startActivity(intentMainActivity);
            finish();
        } else if (id == R.id.nav_SearchScreen) {
            Intent intentSearchScreen = new Intent(SearchScreen.this,SearchScreen.class);
            startActivity(intentSearchScreen);
            finish();
        } else if (id == R.id.nav_Attractions) {
            Intent intentAttractions = new Intent(SearchScreen.this, Attractions.class);
            startActivity(intentAttractions);
            finish();
        } else if (id == R.id.nav_Food) {
            Intent intentFood = new Intent(SearchScreen.this, Food.class);
            startActivity(intentFood);
            finish();
        } else if (id == R.id.nav_Accommidation) {
            Intent intentAccommidation = new Intent(SearchScreen.this,Accommidation.class);
            startActivity(intentAccommidation);
            finish();
        } else if (id == R.id.nav_Entertainment) {
            Intent intentEntertainment = new Intent(SearchScreen.this,Entertainment.class);
            startActivity(intentEntertainment);
            finish();
        } else if (id == R.id.nav_MapsActivity) {
            Intent intentMapsActivity = new Intent(SearchScreen.this,MapsActivity.class);
            startActivity(intentMapsActivity);
            finish();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

}
下面的代码取自“活动搜索”屏幕

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout 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.mcdai.derrytourism.SearchScreen">

        <TextView
            android:id="@+id/txtSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search"
            android:paddingBottom="50sp"
            android:textAlignment="center"
            android:textSize="20sp"
            android:textAppearance="@style/TextAppearance.AppCompat.Body1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/txtFreeTextSearch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Free-Text Search"
            android:textStyle="bold"
            android:textAlignment="center"
            android:textSize="20sp"
            android:paddingBottom="20sp"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:layout_below="@+id/txtSearch"
            android:layout_alignParentLeft="true" />

        <Button
            android:id="@+id/btnSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_alignTop="@+id/txtAccommidationType"
            android:layout_toRightOf="@+id/txtDestination"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="50sp" />

        <TextView
            android:id="@+id/txtAccommidationType"
            android:text="AccommidationType"
            android:textSize="15sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:layout_marginLeft="40dp"
            android:layout_alignBottom="@+id/radioGroup"
            android:layout_toRightOf="@+id/radioGroup"
            android:paddingBottom="10sp" />

        <EditText
            android:id="@+id/editFreeTextSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:ems="10"
            android:inputType="text"
            android:layout_below="@+id/txtFreeTextSearch"
            android:layout_centerHorizontal="true" />

        <Spinner
            android:id="@+id/spinnerAccommidationType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/txtAccommidationType"
            android:layout_alignParentRight="true" />

        <Spinner
            android:id="@+id/spinnerRestaurantType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/txtRestuarantType"
            android:layout_alignParentRight="true"
            android:layout_alignLeft="@+id/spinnerAccommidationType" />

        <TextView
            android:id = "@+id/buttonLogout"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:text = "Logout"
            android:textSize="15sp"
            android:textAlignment="center"
            android:clickable="false"
            android:textColor="@android:color/holo_blue_dark"
            android:onClick="onClick"
            android:paddingBottom="50sp"
            android:layout_alignBaseline="@+id/txtSearch"
            android:layout_alignBottom="@+id/txtSearch"
            android:layout_alignParentRight="true" />

        <TextView
            android:id="@+id/txtMaxPrice"
            android:text="Max(£)"
            android:textSize="10sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textAlignment="center"
            android:layout_above="@+id/editMinPrice"
            android:layout_alignParentRight="true"
            android:layout_alignLeft="@+id/editMaxPrice"
            android:layout_marginBottom="-4sp" />

        <EditText
            android:id="@+id/editMaxPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="5"
            android:hint="10"
            android:textSize="15sp"
            android:textAlignment="center"
            android:background="@android:color/transparent"
            android:inputType="numberDecimal"
            android:layout_marginBottom="21dp"
            android:layout_above="@+id/spinnerRestaurantType"
            android:layout_alignParentRight="true" />

        <TextView
            android:id="@+id/txtMinPrice"
            android:text="Min(£)"
            android:textSize="10sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:textAlignment="center"
            android:layout_above="@+id/editMinPrice"
            android:layout_alignLeft="@+id/editMinPrice"
            android:layout_toLeftOf="@+id/txtMaxPrice"
            android:layout_marginBottom="-4sp"
            android:paddingRight="55sp" />

        <EditText
            android:id="@+id/editMaxDestination"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="5"
            android:hint="10"
            android:textSize="15sp"
            android:background="@android:color/transparent"
            android:textAlignment="center"


            android:inputType="number"
            android:layout_below="@+id/txtDestination"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/txtCriteriaSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Criteria Search"
            android:textStyle="bold"
            android:textAlignment="center"
            android:textSize="20sp"
            android:paddingTop="20sp"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:paddingBottom="10sp"
            android:layout_marginTop="41dp"
            android:layout_below="@+id/editFreeTextSearch"
            android:layout_centerHorizontal="true" />

        <TextView
            android:id="@+id/txtDestination"
            android:text="Max Distance (km)"
            android:textSize="15sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:layout_below="@+id/editFreeTextSearch"
            android:layout_centerHorizontal="true"
            android:paddingTop="10sp" />

        <RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="14sp"
            android:paddingBottom="6sp"
            android:layout_below="@+id/txtCriteriaSearch"
            android:layout_alignParentLeft="true">

            <RadioButton
                android:id="@+id/radioPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="onRadioButtonClicked"
                android:layout_marginTop="10sp"
                android:layout_marginBottom="3sp" />

            <RadioButton
                android:id="@+id/radioRestuarantType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="onRadioButtonClicked"
                android:layout_marginTop="10sp"/>

            <RadioButton
                android:id="@+id/radioAccommidationType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/radioRestuarantType"
                android:onClick="onRadioButtonClicked"
                android:layout_marginTop="15sp" />
        </RadioGroup>

        <EditText
            android:id="@+id/editMinPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="5"
            android:hint="0"
            android:textSize="15sp"
            android:textAlignment="center"
            android:background="@android:color/transparent"
            android:inputType="numberDecimal"
            android:layout_alignBaseline="@+id/editMaxPrice"
            android:layout_alignBottom="@+id/editMaxPrice"
            android:layout_toLeftOf="@+id/buttonLogout"
            android:paddingRight="55sp" />

        <TextView
            android:id="@+id/txtPrice"
            android:text="Price"
            android:textSize="15sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:paddingTop="7sp"
            android:layout_alignTop="@+id/txtMaxPrice"
            android:layout_alignLeft="@+id/txtRestuarantType" />

        <TextView
            android:id="@+id/txtRestuarantType"
            android:text="Restuarant Type"
            android:textSize="15sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="@style/TextAppearance.AppCompat"
            android:layout_marginBottom="26dp"
            android:paddingBottom="2sp"
            android:layout_above="@+id/txtAccommidationType"
            android:layout_alignLeft="@+id/txtAccommidationType"
            android:layout_alignStart="@+id/txtAccommidationType" />

    </RelativeLayout>

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_search_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_search_screen"
        app:menu="@menu/activity_search_screen_drawer" />


</android.support.v4.widget.DrawerLayout>
</ScrollView>

崩溃的原因是ScrollView中有多个子元素。您需要在ScrollView内部的父视图中包装它们,或者将抽屉布局移出ScrollView

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout 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.mcdai.derrytourism.SearchScreen">

    <!-- RelativeLayout Children go here -->

    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        android:fitsSystemWindows="true"
                                        tools:openDrawer="start">

        <include
        layout="@layout/app_bar_search_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

        <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_search_screen"
        app:menu="@menu/activity_search_screen_drawer"/>


     </android.support.v4.widget.DrawerLayout>
</FrameLayout>
</ScrollView>

我不确定你到底想让你的布局看起来像什么,但是如果你按照上面的方法做,你就不会崩溃。确保使用“代码>重新格式化代码”保持缩进一致。祝你好运

请在应用程序崩溃时显示错误日志,这样很容易找到错误。没有错误发生。这就是我遇到问题的原因..04-26 23:48:25.311:E/AndroidRuntime13703:原因:android.view.InflateException:二进制XML文件行285:ScrollView只能承载一个直接子项04-26 23:48:25.311:E/AndroidRuntime13703:原因:java.lang.IllegalStateException:ScrollView只能承载一个直接子项这是在日志cat中生成的在我的设备上运行应用程序CrollView只能承载一个直接子项检查您的scollview!是的,在事件日志中没有显示任何内容,除非我在其他地方查找
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout 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.mcdai.derrytourism.SearchScreen">

    <!-- RelativeLayout Children go here -->

    </RelativeLayout>

    <android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        android:fitsSystemWindows="true"
                                        tools:openDrawer="start">

        <include
        layout="@layout/app_bar_search_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

        <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_search_screen"
        app:menu="@menu/activity_search_screen_drawer"/>


     </android.support.v4.widget.DrawerLayout>
</FrameLayout>
</ScrollView>