[英]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.