【发布时间】:2018-12-11 22:55:58
【问题描述】:
我的应用有问题,我最近开始在 Android Studio 中编码,但遇到了一个我无法解决的问题。 所以我有一个包含 4 个活动的主页,当我在模拟器中运行程序时,应用程序打开并且其中 3 个活动完美运行,但是当我单击打开活动时,我尝试实现滚动条的那个会崩溃。
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
tools:context=".coffeeGrowth" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:keepScreenOn="true"
android:text="@string/large_text"
android:textColor="#008000"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
</ScrollView>
还有崩溃:
07/03 16:54:21:启动应用程序 $ adb install-multiple -r -t -p com.example.android.coffeeknowledge C:\Users\Daud Jawad\CoffeeKnowledge\app\build\intermediates\instant-run-apk\debug\app-debug.apk 拆分安装的 APKs $ adb shell am start -n “com.example.android.coffeeknowledge/com.example.android.coffeeknowledge.MainActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER 客户端尚未准备好..等待进程上线 已连接到 设备 emulator-5554 上的进程 10196 捕获并显示 logcat 来自应用程序的消息。此行为可以在 “调试器”设置页面的“Logcat 输出”部分。 D/: HostConnection::get() 新主机连接建立 0x8aa1c1c0, tid 10196 D/: HostConnection::get() 新主机连接建立 0x8aa1c540,tid 10218 I/OpenGLRenderer:初始化的 EGL,版本 1.4 D/OpenGLRenderer:交换行为 1 W/OpenGLRenderer:选择失败 使用 EGL_SWAP_BEHAVIOR_PRESERVED 进行配置,重试不... D/OpenGLRenderer:交换行为 0 D/EGL_emulation:eglCreateContext: 0x8a9fe920:maj 2 分钟 0 rcv 2 D/EGL_emulation:eglMakeCurrent: 0x8a9fe920:ver 2 0 (tinfo 0x99d98910) W/art:在 Android 4.1 之前, 方法 int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) 会错误地覆盖包私有方法 在 android.widget.ListView D/EGL_emulation: eglMakeCurrent: 0x8a9fe920: 版本 2 0 (tinfo 0x99d98910) D/AndroidRuntime: 正在关闭 VM E/AndroidRuntime: 致命异常: main 进程:com.example.android.coffeeknowledge,PID:10196 java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.android.coffeeknowledge/com.example.android.coffeeknowledge.coffeeGrowth}: java.lang.NullPointerException:尝试调用虚拟方法'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' 在空对象引用上 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 在 android.app.ActivityThread.-wrap12(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:154) 在 android.app.ActivityThread.main(ActivityThread.java:6119) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 引起:java.lang.NullPointerException:尝试调用虚拟方法'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' 在空对象引用上 在 com.example.android.coffeeknowledge.coffeeGrowth.onCreate(coffeeGrowth.java:98) 在 android.app.Activity.performCreate(Activity.java:6679) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 在 android.app.ActivityThread.-wrap12(ActivityThread.java) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android.os.Looper.loop(Looper.java:154) 在 android.app.ActivityThread.main(ActivityThread.java:6119) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 应用程序终止。
谢谢你, 杜德。
【问题讨论】:
-
滚动视图必须只有一个孩子
标签: android crash android-emulator