繁体   English   中英

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

[英]Application crashed while trying to run in emulator

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

这是我的日志记录;

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

因为我是新手, 我无法从此日志中得出任何推论,但我认为一个经验更丰富的开发人员将能够为我提供帮助。

编辑..

源代码:

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"/> 

fragment_main.xml

 <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> 

sorulardburadan.xml

 <?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> 

MainActivity.java

 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; } } } 

密钥在LOGCAT输出的第12行中。 它表明您有一个空指针异常,这意味着您最有可能尝试对实际上为空的变量/属性执行操作。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM