应用程序在尝试在模拟器中运行时崩溃

时间:2015-12-29 16:38:01

标签: java android logcat

我即将完成我的第一个简单项目和TaTa!尝试在Genymotion Emulator中运行我的第一个简单应用程序时出错。

这是我的logcat记录;

12-29 16:34:11.665 1019-1019/com.example.recreated.wedowhatwelearn D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
12-29 16:34:11.705 1019-1019/com.example.recreated.wedowhatwelearn D/libEGL: loaded /system/lib/egl/libEGL_genymotion.so
12-29 16:34:11.709 1019-1019/com.example.recreated.wedowhatwelearn D/: HostConnection::get() New Host Connection established 0xb819c268, tid 1019
12-29 16:34:16.193 1019-1019/com.example.recreated.wedowhatwelearn D/libEGL: loaded /system/lib/egl/libGLESv1_CM_genymotion.so
12-29 16:34:16.197 1019-1019/com.example.recreated.wedowhatwelearn D/libEGL: loaded /system/lib/egl/libGLESv2_genymotion.so
12-29 16:34:22.117 1019-1019/com.example.recreated.wedowhatwelearn W/EGL_genymotion: eglSurfaceAttrib not implemented
12-29 16:34:22.133 1019-1019/com.example.recreated.wedowhatwelearn D/OpenGLRenderer: Enabling debug mode 0
12-29 16:34:22.133 1019-1019/com.example.recreated.wedowhatwelearn D/AndroidRuntime: Shutting down VM
12-29 16:34:22.133 1019-1019/com.example.recreated.wedowhatwelearn W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa627f288)
12-29 16:34:22.209 1019-1022/com.example.recreated.wedowhatwelearn D/dalvikvm: GC_CONCURRENT freed 202K, 4% free 8164K/8455K, paused 71ms+1ms, total 74ms
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime: FATAL EXCEPTION: main
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime: java.lang.NullPointerException
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:392)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.AbsListView.obtainView(AbsListView.java:2267)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ListView.makeAndAddView(ListView.java:1769)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ListView.fillDown(ListView.java:672)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ListView.fillFromTop(ListView.java:733)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.ListView.layoutChildren(ListView.java:1622)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.AbsListView.onLayout(AbsListView.java:2102)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.View.layout(View.java:13754)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:4362)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1866)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1687)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:525)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:615)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:92)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:137)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:4745)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:511)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-29 16:34:22.241 1019-1019/com.example.recreated.wedowhatwelearn E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
12-29 16:34:26.577 1019-1019/? I/Process: Sending signal. PID: 1019 SIG: 9

因为我是途中的新手;我无法从这个logcat中扣除任何东西,但我认为一个更有经验的开发人员可以帮助我..

编辑..

源代码:

activity_main.xml中



<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.recreated.wedowhatwelearn.MainActivity"
   tools:ignore="MergeRootFrame"/>
&#13;
&#13;
&#13;

fragment_main.xml

&#13;
&#13;
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.recreated.wedowhatwelearn.MainActivity$PlaceHolderFragment">

    <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listviewsorular" />


</FrameLayout>
&#13;
&#13;
&#13;

sorulardburadan.xml

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent" android:id="@+id/sorularb1">

</TextView>
&#13;
&#13;
&#13;

MainActivity.java

&#13;
&#13;
package com.example.recreated.wedowhatwelearn;


import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v4.app.Fragment;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }

    }



    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment(){
        }
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
           View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            String[] sorularArray = {

                    "Linguistics - What is the language - 26/06/2015",
                    "Methodology - What is the Metdology - 27/06/2015",
                    "SocioLinguistics - What is the language - 26/06/2015",
                    "Language - What is the Metdology - 27/06/2015",
                    "Approach - What is the language - 26/06/2015",
                    "Syllabus - What is the Metdology - 27/06/2015"

            };

            List<String> sorularıcek = new ArrayList<String>(
                    Arrays.asList(sorularArray));

            ArrayAdapter<String> mSorularAdapter = new ArrayAdapter<String>(
                    getActivity(),
                    R.layout.sorularburadan,
                    R.id.listviewsorular,
                    sorularıcek);

            ListView sorulariste = (ListView) rootView.findViewById(R.id.listviewsorular);
            sorulariste.setAdapter(mSorularAdapter);


            return rootView;
        }
    }


}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

键位于LOGCAT输出的第12行。它显示您有一个空指针异常,这意味着您最有可能尝试对实际上为null的变量/属性执行操作。

从外观上看,这是在数组适配器中发生的。这可能是未正确创建/使用的资源,因此如上所述首先检查这些资源。

如果找不到任何内容,则需要在代码中设置断点来手动调试。首先将断点放在每个Java活动代码的OnCreate方法中。最好的起点是MainActivity的OnCreate。

这很可能在您的资源文件中,因为您似乎正在尝试填充ListView,并且默认的ArrayAdapter无法正确使用该资源。