0

の作成を学んでいますCardView。レイアウト ファイルの [デザイン] タブと、レイアウトのテキスト セクションのプレビュー セクションで、レイアウトがどのように表示されるかを確認できます。

ただし、エミュレーターまたは Android デバイスでアプリを実行すると、「残念ながら、CardActivity動作が停止しました」というエラーがスローされます。

何が悪いのかわからないので、助けてください。

これは activity_main.xml ファイルの内容です。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <!-- A CardView That contains a TextView -->
        <android.support.v7.widget.CardView 
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            card_view:cardUseCompatPadding="true"
            card_view:cardElevation="4dp"
            android:layout_height="wrap_content"
            card_view:cardCornerRadius="5dp"
            android:background="#dddddd">

            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="match_parent"
                android:weightSum="1"
                android:padding="10dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:background="#4f76d2">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:scaleType="centerCrop"
                        android:layout_margin="5dp"
                        android:src="@drawable/image" />

                    <TextView
                        android:id="@+id/info_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/name"
                        android:textSize="?android:attr/textAppearanceLarge"
                        android:layout_margin="20dp"
                        android:textColor="#ffffff"
                        android:textIsSelectable="true" />

                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="@string/para_text"
                    android:textSize="?android:attr/textAppearanceSmall"
                    android:textColor="#88b0f5"
                    android:padding="5dp" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

これは MainActivity.java ファイルの内容です。

package com.example.android.cardactivity;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Android モニターに表示されるのはこれだけです。

04-03 22:55:13.164 20095-20095/com.example.android.cardactivity E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.android.cardactivity, PID: 20095
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.cardactivity/com.example.android.cardactivity.MainActivity}: android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class android.widget.TextView
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
          at android.app.ActivityThread.-wrap11(ActivityThread.java)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:5417)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
       Caused by: android.view.InflateException: Binary XML file line #41: Binary XML file line #41: Error inflating class android.widget.TextView
          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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
          at android.app.Activity.setContentView(Activity.java:2166)
          at com.example.android.cardactivity.MainActivity.onCreate(MainActivity.java:10)
          at android.app.Activity.performCreate(Activity.java:6237)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5417) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
       Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class android.widget.TextView
          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.rInflate(LayoutInflater.java:835)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
          at android.app.Activity.setContentView(Activity.java:2166) 
          at com.example.android.cardactivity.MainActivity.onCreate(MainActivity.java:10) 
          at android.app.Activity.performCreate(Activity.java:6237) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5417) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
       Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Constructor.newInstance(Native Method)
          at android.view.LayoutInflater.createView(LayoutInflater.java:619)
          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.rInflate(LayoutInflater.java:835) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
          at android.app.Activity.setContentView(Activity.java:2166) 
          at com.example.android.cardactivity.MainActivity.onCreate(MainActivity.java:10) 
          at android.app.Activity.performCreate(Activity.java:6237) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5417) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
       Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x1
          at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:666)
          at android.widget.TextView.<init>(TextView.java:1055)
          at android.widget.TextView.<init>(TextView.java:671)
          at android.widget.TextView.<init>(TextView.java:667)
          at java.lang.reflect.Constructor.newInstance(Native Method) 
          at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
          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.rInflate(LayoutInflater.java:835) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
          at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
          at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
          at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
          at android.app.Activity.setContentView(Activity.java:2166) 
          at com.example.android.cardactivity.MainActivity.onCreate(MainActivity.java:10) 
          at android.app.Activity.performCreate(Activity.java:6237) 
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
          at android.app.ActivityThread.-wrap11(ActivityThread.java) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
          at android.os.Handler.dispatchMessage(Handler.java:102) 
          at android.os.Looper.loop(Looper.java:148) 
          at android.app.ActivityThread.main(ActivityThread.java:5417) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
4

1 に答える 1