簡體   English   中英

應用程序崩潰,無法從主要活動轉到另一個活動

[英]Unable to go from main activity to another activity, app is crashing

我的應用程序正在打開,一切正常,但是當我單擊列表時突然崩潰(說...停止了),我創建了一個列表並使用了自定義數組適配器。到現在一切都很好。 但是,當我創建一個新活動並定義了“在項目上單擊偵聽器”集以轉到新活動時,應用突然崩潰。 我不明白為什么。 有人可以幫我解決這個問題嗎?

我試圖使用意圖和捆綁包將數據從主要活動發送到新活動,但是兩者都是相同的。 我已經調整了圖像的大小並應用了它,使其再次崩潰。無論我如何嘗試解決此問題,都無法正常工作((

    -

主要活動

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



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

...

新活動

...

 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)

...

我得到錯誤:

java .lang。 運行時異常:無法啟動活動組件信息:android.view.Inflate異常:二進制XML文件第2行:在android.app.Activity Thread.perform啟動活動中膨脹類android.support.design.widget.Coordinator布局時出錯。在android.app.Activity Thread.handle處啟動Activity Thread.java:2298)在android.app.Activity處啟動Activity(Activity Thread.java:2360)在android.app.Activity處啟動$ 800(Activity Thread.java:144)線程$ H.handle消息(Activity Thread.java:1278)在android上。 處理程序。 調度消息(Handler.java:102)

布局由NewACTİ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>

試過您的代碼,問題出在庫中。

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

問題是產生當加載CountriesSpecialitesActivity ,在該活動使用的setContentView()加載布局具有像在logcat的消息中描述的錯誤:

無法啟動活動組件信息:android.view.Inflate異常:二進制XML文件第2行:在android.app.Activity上膨脹類android.support.design.widget.Coordinator布局時出錯

第2行是:

<android.support.design.widget.CoordinatorLayout

檢查你的活動CountriesSpecialitesActivity從擴展AppCompatActivity類。

class CountriesSpecialitesActivity: AppCompatActivity() {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM