当前位置: 首页 > 知识库问答 >
问题:

我的应用程序不断崩溃(致命异常)

融烨磊
2023-03-14

我的应用程序打开与启动屏幕正常,但不能继续到主屏幕和崩溃!我正在尝试使tablayout(代码中没有错误)

public class MainActivity extends FragmentActivity {
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tabLayout = findViewById(R.id.tablayout_id);
    appBarLayout = findViewById(R.id.appbarid);
    viewPager = findViewById(R.id.viewpager_id);
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

    adapter.AddFragment(new FragmentQuiz(),"Quiz");
    adapter.AddFragment(new FragmentExplore(), "Explore");
    adapter.AddFragment(new FragmentStore(), "Store");

    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
}}
<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="vertical">


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="center"
    app:elevation="0dp"
    android:id="@+id/appbarid">

    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:src="@drawable/image" />

</android.support.design.widget.AppBarLayout>
<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabMode="fixed"
    android:id="@+id/tablayout_id"
    app:tabTextColor="@color/tabtextcolor"
    app:tabIndicatorColor="@color/tabindicatorcolor"
    android:background="@color/tab"/>
<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewpager_id"
    >
</android.support.v4.view.ViewPager>

共有1个答案

艾学海
2023-03-14

您需要在AndroidManifest.xml中为应用程序定义主题,例如:

<application
.....
        android:theme="@style/Theme">

并在values/styles.xml文件中定义了此样式,如下所示:

<style name="Theme" parent="Theme.AppCompat.Light">
.....
</style>
 类似资料:
  • 不管怎样,我一直在Nexus 5中使用LG G watch,但几天后,Android Wear应用程序不断崩溃,即我一遍又一遍地收到“Android Wear意外停止”的对话框。它到了我不得不卸载Wear应用程序的地步,从而使戴G手表变得毫无意义!立即重新安装应用程序会导致同样的结果。几天后我重新安装了应用程序(看到更新已经被推送),它很好,但几天后:同样的事情发生了。 logcat输出显示: E

  • 我正在使用内置于Web View的Android开发浏览器。其中我面临的一个问题是,当我访问http://crashmybrowser.com测试浏览器上的选项卡崩溃时,我的整个浏览器应用程序都会崩溃。但是,当在chrome或Opera上进行相同的测试时,这些浏览器会在崩溃中幸存下来,并且只有特定的选项卡崩溃是由于访问上述网站而预期的结果。有人能帮助理解我如何在使用Webview的浏览器上处理此崩

  • 在现有项目中安装并配置和后,崩溃我的应用程序。 我的应用程序依赖项的一部分:

  • 这里是Android开发者新手。我在MainActivity中使用recyclerview,应用程序不断崩溃。 任何帮助都将受到赞赏! 编辑:对不起,我是新来的。我已经附加了Logcat。和其他xml文件。谢谢 这是我的代码: 列出你的布局。xml: activity_main.xml: } ProductAdapter。java类: } Logcat: 致命异常:主进程:e.wolverine2

  • 注意:在我添加广告之前,我的应用程序运行良好,使用相同的方法 当我试图将adview添加到我的应用程序时,它会使我的应用程序崩溃,所以我删除了它,但仍然给我这个这是logcat 10-12 21:33:19.765 4993-4993/com。fm360。almorfis E/AndroidRuntime:致命异常:主进程:com。fm360。阿尔莫菲斯,PID:4993爪哇。lang.Runti

  • 我有一个制作android应用程序的学校项目。但当我运行应用程序时,它会在logcat中不断显示类似的内容。我是android studio的新手。请帮帮我。