在intent
显示
Logcat
时
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d09b20)
06-14 11:16:24.513 4507-4507/com.infinity.wall_to_paper E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.infinity.wall_to_paper, PID: 4507
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infinity.wall_to_paper/com.infinity.wall_to_paper.Settings}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.infinity.wall_to_paper.Settings.onCreate(Settings.java:22)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.infinity.wall_to_paper.Settings.onCreate(Settings.java:22)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2110)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3554)
at android.view.ViewGroup.<init>(ViewGroup.java:470)
at android.widget.LinearLayout.<init>(LinearLayout.java:176)
at android.widget.LinearLayout.<init>(LinearLayout.java:172)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.infinity.wall_to_paper.Settings.onCreate(Settings.java:22)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
我的计划是:
public class HomeScreen extends AppCompatActivity{
ImageView show_cat,settings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//MainScreen
show_cat=(ImageView)findViewById(R.id.show_cat);
settings=(ImageView)findViewById(R.id.setting_show_fragment);
}
public void showCat(View view){
//on click method
new MyCustomAsyncTask(this).execute();
}
public void showSettings(View view){
//on click method
Intent i= new Intent(this, Settings.class);
startActivity(i);
}}
我正在使用Async task
:
public class MyCustomAsyncTask扩展AsyncTask { 私有上下文上下文;
public MyCustomAsyncTask(Context context){
this.context=context;
}
@Override
protected void onPreExecute() {
// write show progress Dialog code here
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// write service code here
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Intent intent = new Intent(context, Categories.class);
context.startActivity(intent);
}
}
类别的布局文件是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/wallpaper_category">
<ImageView
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/sports"
android:src="@drawable/sports"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/sports"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/nature"
android:layout_alignStart="@+id/nature"
android:onClick="openSports" />
<ImageView
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/love"
android:src="@drawable/love"
android:layout_above="@+id/movies"
android:layout_toLeftOf="@+id/sports"
android:layout_toStartOf="@+id/sports"
android:contentDescription="@string/love"
android:onClick="openLove" />
<ImageView
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/movies"
android:src="@drawable/movies"
android:layout_alignBottom="@+id/nature"
android:layout_toLeftOf="@+id/nature"
android:layout_toStartOf="@+id/nature"
android:contentDescription="@string/movies"
android:onClick="openMovies" />
<ImageView
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/superhero"
android:src="@drawable/superhero"
android:layout_below="@+id/movies"
android:layout_alignRight="@+id/movies"
android:layout_alignEnd="@+id/movies"
android:contentDescription="@string/superhero"
android:onClick="openSuperhero" />
<ImageView
android:layout_width="140dp"
android:layout_height="140dp"
android:id="@+id/cartoons"
android:src="@drawable/cartoons"
android:focusable="false"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/cartoons"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clickable="true"
android:focusableInTouchMode="false"
android:onClick="openCartoons" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/artistic"
android:src="@drawable/artistic"
android:layout_alignTop="@+id/nature"
android:layout_alignLeft="@+id/animals"
android:layout_alignStart="@+id/animals"
android:contentDescription="@string/artistic"
android:onClick="openArtistic" />
<ImageView
android:layout_width="150dp"
android:layout_height="140dp"
android:id="@+id/animals"
android:layout_gravity="center_vertical|right"
android:src="@drawable/animals"
android:layout_above="@+id/artistic"
android:layout_toRightOf="@+id/sports"
android:layout_toEndOf="@+id/sports"
android:contentDescription="@string/animals"
android:onClick="openAnimals" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/vehicles"
android:src="@drawable/vehicles"
android:layout_below="@+id/artistic"
android:layout_alignLeft="@+id/artistic"
android:layout_alignStart="@+id/artistic"
android:contentDescription="@string/vehicles"
android:onClick="openVehicles" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/nature"
android:src="@drawable/nature"
android:layout_centerVertical="true"
android:layout_alignLeft="@+id/cartoons"
android:layout_alignStart="@+id/cartoons"
android:contentDescription="@string/nature"
android:onClick="openNature" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/back_to_main"
android:contentDescription="@string/back_going"
android:background="@drawable/back_going"
android:onClick="onClickBack"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/sports"
android:layout_alignEnd="@+id/sports"
android:layout_marginRight="220dp" />
答案 0 :(得分:0)
您要设置为背景的图像 drawable / wallpaper_category导致Out of Memory异常。
删除布局文件的第2行,它将在没有任何崩溃的情况下运行。
您需要使用Glide或Picasso有效地加载图像。