我的应用程序正在打开,一切正常,但是当我单击列表时,突然崩溃(说....已停止),我创建了一个列表并使用了自定义数组适配器。直到现在一切都很好。但是当我创建一个新 Activity 并定义设置“On Item Click Listener”以转到新 Activity 时,应用程序突然崩溃。我不明白为什么。有人可以帮我解决这个问题吗?
我尝试使用 Intent 和 bundle 将数据从主 Activity 发送到新 Activity ,但它们都是相同的。我已经调整了图像大小并应用了它,它再次崩溃。无论我一直试图解决问题,都不起作用((
-
-
主要 Activity
ListCountries.setOnItemClickListener { parent, view , position, id ->
intent=Intent(this@MainActivity,CountriesSpecialitesActivity::class.java)
intent.putExtra("ıtemClickedPosition",position)
intent.putExtra("allCountriesİnfos",allCountriesInformations)
startActivity(intent)
}
...
新 Activity
...
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 . 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)
由新 Activity 加载的布局
<?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}'
关于java - 无法从主要 Activity 转到另一个 Activity ,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57732811/