我知道,通常你会让我检查日志(在崩溃之前,看看是否有遗漏的内容)。但是无论如何,当我尝试启动新活动时,应用程序都会崩溃。唯一有效的两个活动是SplashScreen
和SignIn
。
为了找出问题,我做了一些简单的尝试。
public class SplashScreen extends AppCompatActivity{
private final static String TAG = SplashScreen.class.getSimpleName();
private final static int DELAY = 2000;
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
startActivity(new Intent(this, Root.class));
finish();
}
以及 Root.class
public class Root extends AppCompatActivity {
private final static String TAG = Root.class.getSimpleName();
private long backPressedTime = 0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
Log.i(TAG, "super.onCreate");
setContentView(R.layout.trending);
Log.i(TAG, "setContentView");
}
我设置了一些日志,看起来我跳到了第二个日志..第三个日志里的setcontentView
在控制台上没有显示。问题更加奇怪的是,无论我尝试启动什么类,都会出现相同的问题。
提及:
检查了日志,没有任何异常(一个警告
03-13 13:52:33.302 23233-23233/com.example.codkom.shirtex W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg --debuggable ...
我花了几天时间在我的个人设备上开发应用并进行了测试(没有任何问题,即使现在也没有),但是在其他设备上却不能正常运行。
如果算的话,我使用multidex,我重写了我的
Application
类,并根据文档执行了Multidex.install(context);
(之所以这么说是因为我猜测可能是由Multidex引起的,但在API 21+上进行了测试,没有使用multidex,结果还好(因为API 21+自己处理multidex)。我的项目中有7个活动,在其中3个活动中出现问题。
我已经不知道还能做什么了..所以这就是我为什么来这里提出这个问题的原因。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cl_"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:background="@drawable/overlay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
app:layout_scrollFlags="enterAlways|scroll"
app:navigationIcon="@drawable/ic_hamburger_menu">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_15_dp"
android:id="@+id/fab_"
android:backgroundTint="@color/blue"
app:fabSize="normal"
android:src="@drawable/ic_plus"
app:layout_anchor="@id/content_frame"
app:layout_anchorGravity="center|bottom"
app:layout_behavior="com.example.codkom.shirtex.ScrollAwareFABBehavior"/>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<include layout="@layout/mainmenu_activity"/>
</android.support.design.widget.NavigationView>
在清单文件中
<application
android:name=".application.ShirTexApp"
android:allowBackup="true"
android:icon="@drawable/ic_app_logo"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat"
android:fullBackupContent="true">
<activity android:name=".activities.Root" android:theme="@style/Theme.AppCompat.Light.NoActionBar" android:windowSoftInputMode="adjustPan"/>
</application>
R.layout.trending
吗? - Rahul