gpt4 book ai didi

java - 将 MainActivity.java 移动到子文件夹中后执行失败

转载 作者:行者123 更新时间:2023-12-01 10:23:07 25 4
gpt4 key购买 nike

我目前正在开发我的 Android 项目。就像标题所示,我将 MainActivity.java 文件移动到我的 Activitys 包中,我这样做是因为我的一个 friend 出于概述的原因建议我这样做。现在,在启动、构建和安装工程 finde 后,我收到以下错误代码。

我的项目可以查看:https://github.com/SchoolGuy/GCFunde

02-17 19:39:24.890  16607-16607/de.noname.enno.gcfunde E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.noname.enno.gcfunde, PID: 16607
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
at android.widget.AbsListView.obtainView(AbsListView.java:2483)
at android.widget.ListView.makeAndAddView(ListView.java:1864)
at android.widget.ListView.fillDown(ListView.java:698)
at android.widget.ListView.fillFromTop(ListView.java:759)
at android.widget.ListView.layoutChildren(ListView.java:1673)
at android.widget.AbsListView.onLayout(AbsListView.java:2271)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1034)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:744)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1180)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:757)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
at android.view.View.layout(View.java:15695)
at android.view.ViewGroup.layout(ViewGroup.java:4981)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2209)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1943)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1126)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6041)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:792)
at android.view.Choreographer.doCallbacks(Choreographer.java:596)
at android.view.Choreographer.doFrame(Choreographer.java:557)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:778)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5727)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
at com.android.internal.os.
02-17 19:39:28.163 16607-16607/de.noname.enno.gcfunde D/Process﹕ killProcess, pid=16607
02-17 19:39:28.173 16607-16607/de.noname.enno.gcfunde D/Process﹕ com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:138 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690

如果你能帮助我,那就太好了。顺便说一句,我正在使用 IntelliJ 15.0.2,并且我已经做了“无效缓存并重新启动”。据我所知,我认为问题不直接出现在我的类(class)中。

提前致谢,学校_guy

最佳答案

这似乎是一个 ListView 问题 - 可能您的 getView 方法返回 null 而不是实际的 View 对象。检查您的 ListAdapter 实现,并确保永远不会在 public View getView(intposition, View ConvertView, ViewGroupparent) 方法中返回 null。

正如我从 GeocacheListAdapter.java 中的代码中看到的,if 语句是错误的 - 检查应该是 if (convertView == null) 而不是 if(convertView != null)

if (convertView == null) {
Holder holder = new Holder();
convertView = layoutInflater.inflate(R.layout.row_layout, null);
//...
}

关于java - 将 MainActivity.java 移动到子文件夹中后执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35465082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com