3

私は Android を初めて使用し、アプリの実行中に Logcat で多くのエラーが発生します。

11-26 16:21:42.787: E/AndroidRuntime(1103): FATAL EXCEPTION: main
11-26 16:21:42.787: E/AndroidRuntime(1103): java.lang.RuntimeException: Unable to    start activity ComponentInfo{com.example.trove.sms/com.example.trove.sms.MainMenu}: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.os.Looper.loop(Looper.java:137)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Method.invokeNative(Native Method)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Method.invoke(Method.java:511)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at dalvik.system.NativeStart.main(Native Method)
11-26 16:21:42.787: E/AndroidRuntime(1103): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.android.internal.widget.ActionBarView
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at   android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2784)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2844)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.Activity.setContentView(Activity.java:1867)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.example.trove.sms.MainMenu.onCreate(MainMenu.java:35)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.Activity.performCreate(Activity.java:5008)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-26 16:21:42.787: E/AndroidRuntime(1103):     ... 11 more
11-26 16:21:42.787: E/AndroidRuntime(1103): Caused by: java.lang.reflect.InvocationTargetException
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Constructor.constructNative(Native Method)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
11-26 16:21:42.787: E/AndroidRuntime(1103):     ... 25 more
11-26 16:21:42.787: E/AndroidRuntime(1103): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.widget.TextView
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.widget.ActionBarView.initTitle(ActionBarView.java:763)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.widget.ActionBarView.setDisplayOptions(ActionBarView.java:596)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at com.android.internal.widget.ActionBarView.<init>(ActionBarView.java:238)
11-26 16:21:42.787: E/AndroidRuntime(1103):     ... 28 more
11-26 16:21:42.787: E/AndroidRuntime(1103): Caused by: java.lang.reflect.InvocationTargetException
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Constructor.constructNative(Native Method)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
11-26 16:21:42.787: E/AndroidRuntime(1103):     ... 38 more
11-26 16:21:42.787: E/AndroidRuntime(1103): Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.content.res.TypedArray.getColor(TypedArray.java:326)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.widget.TextView.<init>(TextView.java:499)
11-26 16:21:42.787: E/AndroidRuntime(1103):     at android.widget.TextView.<init>(TextView.java:442)
11-26 16:21:42.787: E/AndroidRuntime(1103):     ... 41 more

私はアクションバーを使用していないので、問題を見つけることができません.エラーを生成するコード行は

public void onCreate(Bundle savedInstanceState) 
{
 super.onCreate(savedInstanceState);
 setContentView(R.layout.mainmenu)//line 35;
 gridView = (GridView) findViewById(R.id.gridView1);
 gridView.setAdapter(new iconadapter(this)); ....
 }

私のメインメニューxmlファイルは

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!--android:background="#000000"-->
</GridView>

インターネットで数時間検索しましたが、解決策が見つかりません。どんな種類の助けも大歓迎です。

これは私のiconadapterクラスであり、最初は小文字を使用していましたが、これは問題ですか?

public class iconadapter extends BaseAdapter {
private Context context;
private final String icon_text[]={"CREATE MESSAGE","LIST  MESSAGES","BACKUP/RESTORE","SETTINGS","ABOUT"};

public iconadapter(Context context) 
{
    this.context = context;

}

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    if (convertView == null) 
    {

        gridView = new View(context);

        // get layout from mobile.xml
        gridView = inflater.inflate(R.layout.icons, null);

        // set value into textview
        TextView textView = (TextView) gridView
                .findViewById(R.id.grid_item_label);
        textView.setText(icon_text[position]);

        // set image based on selected text
        ImageView imageView = (ImageView) gridView
                .findViewById(R.id.grid_item_image);

        String icon_label = icon_text[position];

        if (icon_label.equals("CREATE MESSAGE")) {
            imageView.setImageResource(R.drawable.create);
        } else if (icon_label.equals("LIST MESSAGES")) {
            imageView.setImageResource(R.drawable.mesage);
        } else if (icon_label.equals("BACKUP/RESTORE")) {
            imageView.setImageResource(R.drawable.backup1);
        } else if (icon_label.equals("SETTINGS")){
            imageView.setImageResource(R.drawable.settings);
        }
        else imageView.setImageResource(R.drawable.about);

    } else {
        gridView = (View) convertView;
    }

    return gridView;
}

public int getCount() {
    // TODO Auto-generated method stub
    return icon_text.length;
}

public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return 0;
}
 }

ここでは、アプリのアイコンを設定しています。これは単なる異なるオプションであり、画像に対応するラベルを意味します。私が膨らませているiconadapterのxmlファイルは

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" 
android:orientation="vertical"
android:background="#000000">

<ImageView
    android:id="@+id/grid_item_image"
    android:layout_width="70sp"
    android:layout_height="70sp"
    android:src="@drawable/create" 
     android:contentDescription="@string/desc">
</ImageView>

<TextView
    android:id="@+id/grid_item_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:text="@+id/label"
    android:layout_marginTop="5dp" >
    <!--android:textColor="#ffffff"  -->
</TextView>

</LinearLayout>
4

1 に答える 1

0

iconadapter(this)とは何ですか?
最初に小さな文字でクラスを作成しましたか?
また、iconadapterで何をしているのかを知る必要があります。

于 2012-11-26T12:13:04.470 に答える