简体   繁体   中英

Unable to go from main activity to another activity, app is crashing

my app is opening , everything is normal but when I click the list, suddenly crashing(says....has stopped),I created a list and used custom array adapter.till now everything is fine. but when I created a new activity and defined set On Item Click Listener to go to new activity, app is suddenly crashing. I cant understand why. can anybody help me please with that problem?

I tried to send data from main activity to new activity with intent and bundle but both of them are the same. I have resized the images and apply it as well its again crashing.whatever I have been trying to fix the problem ,does not work((

    -

MAİN ACTİVİTY

ListCountries.setOnItemClickListener { parent, view , position, id ->



     intent=Intent(this@MainActivity,CountriesSpecialitesActivity::class.java)
                intent.putExtra("ıtemClickedPosition",position)
                intent.putExtra("allCountriesİnfos",allCountriesInformations)
                startActivity(intent)
            }

...

NEW ACTİVİTY

...

 position=intent.extras?.get("item Clicked Position") as Int
    all Countries Information=intent.extras?.get("all Countries İnfo") as 
    Array List<Country>    


text view Country Spec. set Text(all County Info.get(position).countries Gen Spec)

...

I get error:

java .lang . Run time Exception : Unable to start activity Component Info: android.view.Inflate Exception: Binary XML file line #2: Error inflating class android.support.design.widget.Coordinator Layout at android.app.Activity Thread.perform Launch Activity(Activity Thread.java:2298) at android.app.Activity Thread.handle Launch Activity(Activity Thread.java:2360) at android.app.Activity Thread.access$800(Activity Thread.java:144) at android.app.Activity Thread $H.handle Message(Activity Thread.java:1278) at android . Handler. dispatch Message(Handler.java:102)

layout loaded by New ACTİVİTY

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="100dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/kara_buyu_buyuk"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"/>


            <View
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:layout_gravity="bottom"
                android:background="@drawable/scrim"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android .support. design .widget. App Bar Layout>

    <android x. core. widget. Nested Scroll View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/  app bar_scrolling_view_behavior">

        <Linear Layout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <Text View
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/text view Country Spec">

            </Text View>

        </Linear Layout>


    </android x. core.widget. Nested Scroll View>


</android. support. design. widget. Coordinator Layout>

Tried your code, the problem is with the library.

implementation 'com.android.support:appcompat-v7:{yourversion}' // appcompat library
implementation 'com.android.support:design:{yourversion}'

The problem is generated when you load CountriesSpecialitesActivity , in this Activity the layout loaded using setContentView() has an error like is described in the LogCat message:

Unable to start activity Component Info: android.view.Inflate Exception: Binary XML file line #2: Error inflating class android.support.design.widget.Coordinator Layout at android.app.Activity

The line #2 is:

<android.support.design.widget.CoordinatorLayout

check if your Activity CountriesSpecialitesActivity is extending from AppCompatActivity class.

class CountriesSpecialitesActivity: AppCompatActivity() {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM