我最近在Play商店上发布了我的应用程序,引起了我的注意,该应用程序在某些设备上崩溃了。我已经对自己进行了多次测试,完全没有问题。
我没有太多阅读日志的经验,我自己也无法弄清楚问题所在。我知道该错误位于某个特定位置,但是我怎么知道导致此错误的原因呢?
以下是发生错误的类中的代码:
package com.apps.robloxmusic;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class Dashboard extends AppCompatActivity {
private LinearLayout musicCodes;
private LinearLayout twitterCodes;
private LinearLayout artistSearch;
private LinearLayout discordOpen;
private LinearLayout categorySearch;
private LinearLayout websiteOpen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
//Init Mobile Ads
MobileAds.initialize(this,"XXXXXXXXXXX");
//Dashboard ---> Music Codes
musicCodes = (LinearLayout) findViewById(R.id.musicCodesButton);
musicCodes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openMusicCodes();
}
});
//Dashboard ---> Twitter Codes
twitterCodes = (LinearLayout) findViewById(R.id.twitterCodesButton);
twitterCodes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openTwitterCodes();
}
});
//Dashboard ---> Artists
artistSearch = (LinearLayout) findViewById(R.id.artistSearchButton);
artistSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openArtistSearch();
}
});
//Dashboard ---> Discord Link
discordOpen = (LinearLayout) findViewById(R.id.discordServerButton);
discordOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openDiscord();
}
});
//Dashboard ---> Categories
categorySearch = (LinearLayout) findViewById(R.id.categorySearchButton);
categorySearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openCategorySearch();
}
});
//Dashboard ---> Website Link
websiteOpen = (LinearLayout) findViewById(R.id.websiteButton);
websiteOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWebsite();
}
});
}
//Methods for Activity changes
public void openMusicCodes() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public void openTwitterCodes() {
Intent intent = new Intent(this, TwitterViewer.class);
startActivity(intent);
}
public void openArtistSearch() {
Intent intent = new Intent(this, Artists.class);
startActivity(intent);
}
public void openDiscord() {
String url = "https://discord.gg/QESMn66";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
public void openCategorySearch() {
Intent intent = new Intent(this, Categories.class);
startActivity(intent);
}
public void openWebsite() {
String url = "http://rocodes.io";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
}
以下是崩溃报告:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2572)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2654)
at android.app.ActivityThread.access$900 (ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1488)
at android.os.Handler.dispatchMessage (Handler.java:111)
at android.os.Looper.loop (Looper.java:207)
at android.app.ActivityThread.main (ActivityThread.java:5728)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.inflate (LayoutInflater.java:539)
at android.view.LayoutInflater.inflate (LayoutInflater.java:423)
at android.view.LayoutInflater.inflate (LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView (AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:140)
at com.apps.robloxmusic.Dashboard.onCreate (Dashboard.java:26)
at android.app.Activity.performCreate (Activity.java:6309)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2519)
Caused by: android.view.InflateException:
at android.view.LayoutInflater.createView (LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView (LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
at android.view.LayoutInflater.inflate (LayoutInflater.java:492)
Caused by: java.lang.reflect.InvocationTargetException:
at java.lang.reflect.Constructor.newInstance (Native Method)
at android.view.LayoutInflater.createView (LayoutInflater.java:619)
Caused by: android.content.res.Resources$NotFoundException:
at android.content.res.Resources.loadDrawableForCookie (Resources.java:2922)
at android.content.res.Resources.loadDrawable (Resources.java:2844)
at android.content.res.TypedArray.getDrawable (TypedArray.java:870)
at android.view.View.<init> (View.java:4001)
at android.view.ViewGroup.<init> (ViewGroup.java:604)
at android.widget.FrameLayout.<init> (FrameLayout.java:115)
at android.widget.ScrollView.<init> (ScrollView.java:185)
at android.widget.ScrollView.<init> (ScrollView.java:181)
at android.widget.ScrollView.<init> (ScrollView.java:177)
相关课程的布局文件:
<ScrollView 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:background="@drawable/dashbg"
tools:context=".Dashboard">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_marginTop="32dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Dashboard"
android:id="@+id/dashTextMain"
android:textSize="34sp"
android:textColor="#FFFFFF"
android:fontFamily="sans-serif-black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/dashTextSub"
android:textSize="20sp"
android:textColor="#E8E8E8"
android:text="Welcome to RoCodes.io,"
android:layout_below="@id/dashTextMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/dashTextSub2"
android:textSize="20sp"
android:textColor="#E8E8E8"
android:text="your home for Roblox codes!"
android:paddingBottom="50dp"
android:layout_below="@id/dashTextSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:src="@drawable/robcodescropped"
android:layout_alignParentRight="true"
android:layout_width="60dp"
android:layout_height="60dp" />
</RelativeLayout>
<GridLayout
android:rowCount="3"
android:columnCount="1"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/musicCodesButton"
android:orientation="vertical"
android:background="#FFFFFF"
android:gravity="center"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/musicicon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="Music Codes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/artistSearchButton"
android:orientation="vertical"
android:background="#FFFFFF"
android:gravity="center"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/artisticon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="Search Artists"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/categorySearchButton"
android:orientation="vertical"
android:background="#FFFFFF"
android:gravity="center"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/categoryicon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="Music Categories"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/discordServerButton"
android:orientation="vertical"
android:gravity="center"
android:background="#FFFFFF"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:src="@drawable/discordicon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="RoCodes Discord"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/twitterCodesButton"
android:orientation="vertical"
android:gravity="center"
android:background="#FFFFFF"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/twittericon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="New Codes"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:id="@+id/websiteButton"
android:orientation="vertical"
android:gravity="center"
android:background="#FFFFFF"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:src="@drawable/websiteicon"
android:layout_width="80dp"
android:layout_height="80dp" />
<TextView
android:layout_marginTop="12dp"
android:textColor="#000000"
android:textSize="18dp"
android:text="RoCodes Website"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>
我真是茫然,这里出了什么问题。在我所有的设备上都能正常工作。
答案 0 :(得分:0)
布局xml文件中有错误。请验证您的布局文件。
答案 1 :(得分:0)
问题是,最低支持SDK为22,但是由于某种原因,我使用的可绘制图标仅受SDK 24支持。因此,SDK 22或23上的任何设备在启动时都会崩溃,因为它们无法在其中加载可绘制对象。
通过使用Android Studio中的内置矢量资源替换自定义可绘制图标来解决。