[英]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 . 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 . 运行时异常:无法启动活动组件信息: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. 处理程序。 dispatch Message(Handler.java:102) 调度消息(Handler.java:102)
layout loaded by New ACTİVİTY 布局由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>
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: 问题是产生当加载CountriesSpecialitesActivity
,在该活动使用的setContentView()加载布局具有像在logcat的消息中描述的错误:
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 无法启动活动组件信息:android.view.Inflate异常:二进制XML文件第2行:在android.app.Activity上膨胀类android.support.design.widget.Coordinator布局时出错
The line #2 is: 第2行是:
<android.support.design.widget.CoordinatorLayout
check if your Activity CountriesSpecialitesActivity
is extending from AppCompatActivity
class. 检查你的活动CountriesSpecialitesActivity
从扩展AppCompatActivity
类。
class CountriesSpecialitesActivity: AppCompatActivity() {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.