Java 无法从主活动转到其他活动,应用程序正在崩溃
我的应用程序正在打开,一切正常,但当我单击列表时,突然崩溃(说…已停止),我创建了一个列表并使用了自定义阵列适配器。到目前为止,一切正常。但当我创建了一个新的活动并定义了set On Item Click Listener以转到新活动时,应用程序突然崩溃了。我不明白为什么。有谁能帮我解决那个问题吗 我试图用intent和bundle将数据从主活动发送到新活动,但两者都是相同的。我已经调整了图片的大小,并将其应用于再次崩溃。无论我试图解决什么问题,都无法解决((Java 无法从主活动转到其他活动,应用程序正在崩溃,java,android,kotlin,Java,Android,Kotlin,我的应用程序正在打开,一切正常,但当我单击列表时,突然崩溃(说…已停止),我创建了一个列表并使用了自定义阵列适配器。到目前为止,一切正常。但当我创建了一个新的活动并定义了set On Item Click Listener以转到新活动时,应用程序突然崩溃了。我不明白为什么。有谁能帮我解决那个问题吗 我试图用intent和bundle将数据从主活动发送到新活动,但两者都是相同的。我已经调整了图片的大小,并将其应用于再次崩溃。无论我试图解决什么问题,都无法解决(( - 马恩法案(MAİN A
-
-
马恩法案(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)
}
<?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>
新法案
ListCountries.setOnItemClickListener { parent, view , position, id ->
intent=Intent(this@MainActivity,CountriesSpecialitesActivity::class.java)
intent.putExtra("ıtemClickedPosition",position)
intent.putExtra("allCountriesİnfos",allCountriesInformations)
startActivity(intent)
}
<?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>
position=intent.extras?.get(“项目点击位置”)为Int
所有国家信息=intent.extras?.get(“所有国家信息”)作为
数组列表
文本查看国家规格设置文本(所有县信息获取(位置)。国家规格)
我得到一个错误:
运行时异常:无法启动活动组件
信息:android.view.Inflate异常:二进制XML文件行#2:错误
膨胀类android.support.design.widget.Coordinator布局
在android.app.Activity Thread.perform启动活动(Activity Thread.java:2298)
在android.app.Activity-Thread.handle启动活动(Activity-Thread.java:2360)
在android.app.Activity-Thread.access$800(Activity-Thread.java:144)
在android.app.Activity线程$H.handle消息中(Activity-Thread.java:1278)
在android.Handler.dispatch消息中(Handler.java:102)
新法案加载的布局
ListCountries.setOnItemClickListener { parent, view , position, id ->
intent=Intent(this@MainActivity,CountriesSpecialitesActivity::class.java)
intent.putExtra("ıtemClickedPosition",position)
intent.putExtra("allCountriesİnfos",allCountriesInformations)
startActivity(intent)
}
<?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>
加载
CountriesSpecialitesActivity
时会产生问题,在此活动中,使用setContentView()加载的布局有一个错误,如LogCat消息中所述:
无法启动活动组件信息:android.view.Inflate
异常:二进制XML文件行#2:膨胀类时出错
android.support.design.widget.Coordinator布局位于
android.app.Activity
第2行是:
尝试了你的代码,问题出在库上
implementation 'com.android.support:appcompat-v7:{yourversion}' // appcompat library
implementation 'com.android.support:design:{yourversion}'
你是否将你的新活动添加到清单中了?我想@Jorgesys是对的,因为要么我在布局上犯了错误,要么我无法添加新的androidx材料支持设计依赖项。添加了xml布局@Jorgesysadded new activity到清单中@BlackHatSamuraiHas有人找到了解决方案吗?Jorgesys你会给出你的答案吗?完成,如果你有其他的解决方案错误请再次检查日志猫@jayzxllmy新活动(CountriesSpecialiesActivity)正在由AppCompativeActivity扩展,因此??日志猫中有任何消息吗