我在Android Studio中遇到了问题。如果我为我的应用程序生成一个apk并安装apk应用程序工作,但当我用模拟器或设备运行我的应用程序时,我收到以下错误:
11-21 13:20:10.248 1191-1191/com.foca.deboInventario E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foca.deboInventario/com.foca.deboInventario.DeboInventario}: android.view.InflateException: Binary XML file line #191: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #191: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.foca.deboInventario.DeboInventario.onCreate(DeboInventario.java:162)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
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:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.foca.deboInventario.DeboInventario.onCreate(DeboInventario.java:162)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000e a=-1 r=0x7f02000e}
at android.content.res.Resources.loadDrawable(Resources.java:1897)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:120)
at android.widget.ImageView.<init>(ImageView.java:110)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
at android.app.Activity.setContentView(Activity.java:1867)
at com.foca.deboInventario.DeboInventario.onCreate(DeboInventario.java:162)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at
dalvik.system.NativeStart.main(Native Method)
11-21 13:20:10.298 152-152/system_process W/ActivityManager: Force finishing activity com.foca.deboInventario/.DeboInventario
11-21 13:20:10.408 1191-1194/com.foca.deboInventario D/dalvikvm: GC_CONCURRENT freed 340K, 4% free 10837K/11271K, paused 20ms+15ms, total 140ms
11-21 13:20:10.738 152-155/system_process D/dalvikvm: GC_CONCURRENT freed 841K, 15% free 17081K/19911K, paused 23ms+24ms, total 296ms
11-21 13:20:10.919 152-166/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{416ab440 com.foca.deboInventario/.DeboInventario}
11-21 13:20:11.008 262-262/com.android.launcher W/EGL_emulation: eglSurfaceAttrib not implemented
11-21 13:20:12.858 1191-1191/? I/Process: Sending signal. PID: 1191 SIG: 9
11-21 13:20:12.868 152-307/system_process I/ActivityManager: Process com.foca.deboInventario (pid 1191) has died.
11-21 13:20:12.928 152-517/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@415a1258 attribute=null
11-21 13:20:21.248 152-166/system_process W/ActivityManager: Activity destroy timeout for ActivityRecord{416ab440 com.foca.deboInventario/.DeboInventario}
在Activity
中,第一个打印语句出现,但第二个不出现。 Activity
上的setContentView
崩溃:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("Here1");
setContentView(R.layout.xml_deboinventario);
System.out.println("Here2");
这是XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondo_recepcion_inventario" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:text="@string/titulo_debo_inventario"
android:textColor="@color/black"
tools:ignore="SpUsage"
android:textSize="25dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<!-- PRIMER BOTON - izquierda -->
<LinearLayout
android:layout_width="200px"
android:layout_height="200px"
android:layout_margin="40px"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/DI_boton_izq"
android:layout_width="@dimen/dim_boton_masgrande"
android:layout_height="@dimen/dim_boton_grande"
android:layout_margin="10px"
android:text="@string/palabra_inventarios"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/continuar_inventarios_en_curso"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
</LinearLayout>
<!-- SEGUNDO BOTON - centro -->
<LinearLayout
android:layout_width="200px"
android:layout_height="200px"
android:layout_margin="40px"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<Button
android:id="@+id/DI_boton_cen"
android:layout_width="@dimen/dim_boton_grande"
android:layout_height="@dimen/dim_boton_grande"
android:layout_margin="10px"
android:text="@string/empezar"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Comenzar Nuevo Inventario"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="200px"
android:layout_height="200px"
android:layout_margin="40px"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/boton_compras"
android:layout_width="@dimen/dim_boton_masgrande"
android:layout_height="@dimen/dim_boton_grande"
android:layout_margin="10px"
android:text="@string/mensaje_boton_acceso_compras"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/acceder_para_cargar_las_compras"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
</LinearLayout>
<LinearLayout
android:layout_width="200px"
android:layout_height="200px"
android:layout_margin="40px"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<Button
android:id="@+id/button2"
android:layout_width="@dimen/dim_boton_grande"
android:layout_height="@dimen/dim_boton_grande"
android:layout_margin="10px"
android:text="@string/empezar"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/comenzar_nuevo_inventario"
android:textColor="@color/black"
android:textSize="@dimen/boton_grande" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/DI_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/palabra_version"
android:textColor="@color/black"
android:textSize="12px"
tools:ignore="RelativeOverlap" />
<TextView
android:id="@+id/DI_idtablet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/palabra_id_terminal"
android:textColor="@color/black"
android:textSize="12px" />
<ImageView
android:id="@+id/DI_imagen_debo"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20px"
android:layout_marginTop="20px"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:visibility="visible"
android:contentDescription=""
tools:ignore="ContentDescription">
</ImageView>
<ImageView
android:id="@+id/DI_imagen_salir"
android:layout_width="40px"
android:layout_height="40px"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="10px"
android:scaleType="fitXY"
android:src="@drawable/boton_salir"
android:visibility="visible"
tools:ignore="ContentDescription">
</ImageView>
<ImageView
android:id="@+id/DI_imagen_config"
android:layout_width="40px"
android:layout_height="40px"
android:layout_alignParentTop="true"
android:layout_margin="10px"
android:layout_toLeftOf="@+id/DI_imagen_salir"
android:src="@drawable/boton_config"
tools:ignore="ContentDescription">
</ImageView>
<ImageView
android:id="@+id/DI_imagen_update"
android:layout_width="50px"
android:layout_height="50px"
android:layout_alignParentTop="true"
android:layout_margin="6px"
android:layout_toLeftOf="@+id/DI_imagen_config"
android:src="@drawable/boton_update"
tools:ignore="ContentDescription">
</ImageView>
</RelativeLayout>
我给了android:background
一种颜色,但仍然遇到同样的问题。
我也尝试过清理和重建项目。
有人可以告诉我问题是什么以及如何解决这个问题? 这可能是由Android Studio中的更新引起的吗?
谢谢!
答案 0 :(得分:0)
我解决了这个问题。更改版本grandle。 Android studio ide更新了一些更改,并在我的项目中编辑了Grandle Scripts / build.grandle。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:2.2.2' Version IDE update
classpath 'com.android.tools.build:gradle:1.5.0' // Version before update
}
}
现在我可以再次运行和调试项目。非常感谢。