缺少库或不正确的代码? Android Studio,APK崩溃

时间:2016-02-29 19:32:41

标签: java android-fragments android-studio

我试图简单地在Activity上显示一个片段,然后为旋转器添加一切工作方法,之后这样做什么都没有用?我尝试通过SDK管理器下载支持库,看看是否会解决这个问题,因为我只能猜测LogCat所指的是什么,有人可能会发现这里发生了什么吗?

MainActivity.java

package com.example.****.testfragments3;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import java.util.ArrayList;
import java.util.Arrays;


public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
    private ArrayList<String> list1;
    private ArrayList<String> list2;
    private ArrayList<String> list3;

    Spinner s1,s2,s3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        s1 = (Spinner)findViewById(R.id.spinner);
        s2 = (Spinner)findViewById(R.id.spinner2);
        s1.setOnItemSelectedListener(this);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        String sp1= String.valueOf(s1.getSelectedItem());

        if(sp1.contentEquals("Nitrates")) {
            list2 = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.list2)));
            ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, list2);
            dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dataAdapter1.notifyDataSetChanged();
            s2.setAdapter(dataAdapter1);
        }

        if(sp1.contentEquals("Phosphates")) {
            list1 = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.list1)));
            ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, list1);
            dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dataAdapter2.notifyDataSetChanged();
            s2.setAdapter(dataAdapter2);
        }

        if(sp1.contentEquals("Alkalinity")) {
            list1 = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.list1)));
            ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, list1);
            dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dataAdapter3.notifyDataSetChanged();
            s2.setAdapter(dataAdapter3);
        }

        if(sp1.contentEquals("Calcium")) {
            list1 = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.list1)));
            ArrayAdapter<String> dataAdapter4 = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, list1);
            dataAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dataAdapter4.notifyDataSetChanged();
            s2.setAdapter(dataAdapter4);
        }

        if(sp1.contentEquals("Magnesium")) {
            list3 = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.list3)));
            ArrayAdapter<String> dataAdapter5 = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, list3);
            dataAdapter5.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            dataAdapter5.notifyDataSetChanged();
            s2.setAdapter(dataAdapter5);
        }

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
}

logcat的

    02-29 10:50:20.140 24382-24382/com.example.nparr.testfragments3 E/Trace: error opening trace file: No such file or directory (2)
    02-29 10:50:20.140 24382-24382/com.example.****.testfragments3 D/ActivityThread: setTargetHeapUtilization:0.25
    02-29 10:50:20.140 24382-24382/com.example.****.testfragments3 D/ActivityThread: setTargetHeapIdealFree:8388608
    02-29 10:50:20.150 24382-24382/com.example.****.testfragments3 D/ActivityThread: setTargetHeapConcurrentStart:2097152
    02-29 10:50:20.181 24382-24382/com.example.****.testfragments3 I/fd: BootstrapApplication created. Android package is com.example.****.testfragments3, real application class is null.
    02-29 10:50:20.191 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve static field 6881 (UTF_8) in Ljava/nio/charset/StandardCharsets;
    02-29 10:50:20.191 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x62 at 0x0006
    02-29 10:50:20.191 24382-24382/com.example.****.testfragments3 V/fd: Cannot find external resources, not patching them in
    02-29 10:50:20.191 24382-24382/com.example.****.testfragments3 I/fd: Resource override is null
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 V/fd: Cannot find newer dex classes, not patching them in
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 I/fd: No override .dex files found
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 1706 (Landroid/util/ArrayMap;) in Lcom/android/tools/fd/runtime/MonkeyPatcher;
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x01cd
    02-29 10:50:20.201 24382-24382/com.example.****.testfragments3 I/fd: Starting server socket listening for package com.example.****.testfragments3 on android.net.LocalSocketAddress@421fec28
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/fd: Started server for package com.example.****.testfragments3
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.Context.getSystemService, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 424: Landroid/content/Context;.getSystemService (Ljava/lang/Class;)Ljava/lang/Object;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0049
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.stopLockTask, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 223: Landroid/app/Activity;.stopLockTask ()V
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x00b7
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 214 (Landroid/os/PersistableBundle;) in Lcom/example/****/testfragments3/MainActivity;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x00ef
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 407: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x00ff
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.onVisibleBehindCanceled, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 146: Landroid/app/Activity;.onVisibleBehindCanceled ()V
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x010f
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 223 (Landroid/os/UserHandle;) in Lcom/example/****/testfragments3/MainActivity;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x011b
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.onWindowStartingActionMode, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 150: Landroid/app/Activity;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0135
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 214 (Landroid/os/PersistableBundle;) in Lcom/example/****/testfragments3/MainActivity;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x0198
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 175 (Landroid/media/session/MediaController;) in Lcom/example/****/testfragments3/MainActivity;
    02-29 10:50:20.211 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x01b0
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve check-cast 1866 (Landroid/widget/Toolbar;) in Lcom/example/****/testfragments3/MainActivity;
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x01ba
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.releaseInstance, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 157: Landroid/app/Activity;.releaseInstance ()Z
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x02db
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.onActivityReenter, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 98: Landroid/app/Activity;.onActivityReenter (ILandroid/content/Intent;)V
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x02f2
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.ContextWrapper.getCodeCacheDir, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 476: Landroid/content/ContextWrapper;.getCodeCacheDir ()Ljava/io/File;
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0347
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.ContextWrapper.createConfigurationContext, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 456: Landroid/content/ContextWrapper;.createConfigurationContext (Landroid/content/res/Configuration;)Landroid/content/Context;
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x03d5
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/FragmentActivity;.dispatchFragmentsOnCreateView (Landroid/view/View;Ljava/lang/String;Landroid/content/Context;Landroid/util/AttributeSet;)Landroid/view/View; from Lcom/example/****/testfragments3/MainActivity;)
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1987: Landroid/support/v4/app/FragmentActivity;.dispatchFragmentsOnCreateView (Landroid/view/View;Ljava/lang/String;Landroid/content/Context;Landroid/util/AttributeSet;)Landroid/view/View;
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0430
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.app.Activity.getVoiceInteractor, referenced from method com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 77: Landroid/app/Activity;.getVoiceInteractor ()Landroid/app/VoiceInteractor;
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x048e
    02-29 10:50:20.221 24382-24382/com.example.****.testfragments3 E/dalvikvm: Could not find class com.example.****.testfragments3.MainActivity.access$super
    02-29 10:50:20.231 24382-24382/com.example.****.testfragments3 testfragments3 D/dalvikvm: VFY: replacing opcode 0x1f at 0x07e6
    02-29 10:50:20.231 24382-24382/com.example.****.testfragments3 W/dalvikvm: DexOpt: resolve class illegal access: Lcom/example/ 0x0002
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 14713: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0007
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 666: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
    02-29 10:50:20.361 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
    02-29 10:50:20.371 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
    02-29 10:50:20.371 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 688: Landroid/content/res/TypedArray;.getType (I)I
    02-29 10:50:20.371 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performSaveInstanceState (Landroid/os/Bundle;)V from Lcom/example/****/testfragments3/frag1;)
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performSaveInstanceState, referenced from method com.example.****.testfragments3.frag1.access$super
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1938: Landroid/support/v4/app/Fragment;.performSaveInstanceState (Landroid/os/Bundle;)V
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0041
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.restoreViewState (Landroid/os/Bundle;)V from Lcom/example/****/testfragments3/frag1;)
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.Fragment.restoreViewState, referenced from method com.example.****.testfragments3.frag1.access$super
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1943: Landroid/support/v4/app/Fragment;.restoreViewState (Landroid/os/Bundle;)V
    02-29 10:50:20.411 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0054
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performCreateView (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View; from Lcom/example/****/testfragments3/frag1;)
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performCreateView, referenced from method com.example.****.testfragments3.frag1.access$super
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1928: Landroid/support/v4/app/Fragment;.performCreateView (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View;
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0080
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performPrepareOptionsMenu (Landroid/view/Menu;)Z from Lcom/example/****/testfragments3/frag1;)
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performPrepareOptionsMenu, referenced from method com.example.****.testfragments3.frag1.access$super
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1935: Landroid/support/v4/app/Fragment;.performPrepareOptionsMenu (Landroid/view/Menu;)Z
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x0089
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: DexOpt: illegal method access (call Landroid/support/v4/app/Fragment;.performStop ()V from Lcom/example/****/testfragments3/frag1;)
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.support.v4.app.Fragment.performStop, referenced from method com.example.****.testfragments3.frag1.access$super
    02-29 10:50:20.421 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 1940: Landroid/support/v4/app/Fragment;.performStop ()V
    02-29 10:50:20.471 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 409: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
    02-29 10:50:20.471 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6e at 0x0004
    02-29 10:50:20.481 24382-24382/com.example.****.testfragments3 I/dalvikvm: Could not find method android.widget.PopupWindow.showAsDropDown, referenced from method android.support.v7.widget.AppCompatPopupWindow.showAsDropDown
    02-29 10:50:20.481 24382-24382/com.example.****.testfragments3 W/dalvikvm: VFY: unable to resolve virtual method 15394: Landroid/widget/PopupWindow;.showAsDropDown (Landroid/view/View;III)V
    02-29 10:50:20.481 24382-24382/com.example.****.testfragments3 D/dalvikvm: VFY: replacing opcode 0x6f at 0x000d
    02-29 10:50:20.491 24382-24382/com.example.****.testfragments3 I/AppCompatDelegate: The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's
    02-29 10:50:20.491 24382-24382/com.example.****.testfragments3 D/AndroidRuntime: Shutting down VM
    02-29 10:50:20.491 24382-24382/com.example.****.testfragments3 W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41541438)
    02-29 10:50:20.501 24382-24382/com.example.****.testfragments3 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.****.testfragments3/com.example.****.testfragments3.MainActivity}: java.lang.IllegalStateException: Already attached
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
                                                                                          at android.app.ActivityThread.access$700(ActivityThread.java:139)
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                          at android.os.Looper.loop(Looper.java:137)
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:4918)
                                                                                          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:1004)
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
                                                                                          at dalvik.system.NativeStart.main(Native Method)
                                                                                       Caused by: java.lang.IllegalStateException: Already attached
                                                                                          at android.support.v4.app.FragmentManagerImpl.attachController(FragmentManager.java:2025)
                                                                                          at android.support.v4.app.FragmentController.attachHost(FragmentController.java:95)
                                                                                          at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:276)
                                                                                          at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:61)
                                                                                          at com.example.****.testfragments3.MainActivity.onCreate(MainActivity.java:28)
                                                                                          at android.app.Activity.performCreate(Activity.java:5048)
                                                                                          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
                                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
                                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113) 
                                                                                          at android.app.ActivityThread.access$700(ActivityThread.java:139) 
                                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224) 
                                                                                          at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                          at android.os.Looper.loop(Looper.java:137) 
                                                                                          at android.app.ActivityThread.main(ActivityThread.java:4918) 
                                                                                          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:1004) 
                                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) 
                                                                                          at dalvik.system.NativeStart.main(Native Method) 
    02-29 10:50:34.085 24382-24382/com.example.****.testfragments3 I/Process: Sending signal. PID: 24382 SIG: 9

1 个答案:

答案 0 :(得分:2)

你正在调用super.onCreate两次,实际上也是setContentView。删除过多的电话,你应该没事。

通过告诉您在第28行执行时已经附加了堆栈跟踪非常清楚。

Caused by: java.lang.IllegalStateException: Already attached at android.support.v4.app.FragmentManagerImpl.attachController(FragmentManager.java:2025) at android.support.v4.app.FragmentController.attachHost(FragmentController.java:95) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:276) at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:61) at com.example.****.testfragments3.MainActivity.onCreate(MainActivity.java:28)

我估计如果你密切注意那个日志并且看着第28行,你可能已经注意到了发生了什么。这与缺少的库无关。