Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当我尝试实现滚动条时,我的应用程序崩溃_Android_Crash_Android Emulator - Fatal编程技术网

Android 当我尝试实现滚动条时,我的应用程序崩溃

Android 当我尝试实现滚动条时,我的应用程序崩溃,android,crash,android-emulator,Android,Crash,Android Emulator,我的应用程序有问题,我最近开始在Android studio中编写代码,但我遇到了一个无法解决的问题。 因此,我有一个包含4个活动的主页,当我在emulator中运行程序时,应用程序会打开,其中3个活动工作正常,但我尝试实现滚动条的主页在单击打开活动时崩溃 代码如下: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/andro

我的应用程序有问题,我最近开始在Android studio中编写代码,但我遇到了一个无法解决的问题。 因此,我有一个包含4个活动的主页,当我在emulator中运行程序时,应用程序会打开,其中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安装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外壳am开始-n “com.example.android.coffeeknowledge/com.example.android.coffeeknowledge.MainActivity” -a android.intent.action.MAIN-c android.intent.category.LAUNCHER客户端尚未就绪..正在等待进程联机连接到 处理10196设备仿真器-5554捕获和显示logcat 来自应用程序的消息。可以在中禁用此行为 “调试器”设置页面的“Logcat输出”部分。D/: HostConnection::get()已建立新主机连接0x8AA1C0,tid 10196 D/:HostConnection::get()已建立新主机连接 0x8aa1c540,tid 10218 I/OpenGLRenderer:初始化EGL,版本1.4 D/OpenGLRenderer:交换行为1 W/OpenGLRenderer:未能选择 配置时保留EGL\u交换\u行为,重试时不带。。。 D/OpenGLRenderer:交换行为0 D/EGL_仿真:eglCreateContext: 0x8a9fe920:maj 2 min 0 rcv 2 D/EGL_仿真: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_仿真中:eglMakeCurrent: 0x8a9fe920:版本2 0(tinfo 0x99d98910)D/AndroidRuntime:正在关闭 VM E/AndroidRuntime:致命异常:主 进程:com.example.android.coffeeknowledge,PID:10196 java.lang.RuntimeException:无法启动activity 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) 申请终止

谢谢,,
Daud.

我的朋友,你的XML错了

滚动视图不是布局选项。这是一种观点。因此,您需要围绕scrollview包装布局。请记住,ScrollView只能有一个子视图

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >

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

   </ScrollView>

</RelativeLayout>


scrollview必须只有一个孩子我现在明白了,我发现一些教程没有很好地解释这一点。我尝试了代码,但仍然以同样的方式崩溃。您是否显示了正确的代码?你说的是滚动条。你一定没有展示别的东西。你能粘贴logcat错误吗?我添加了错误,并在日志中显示下午4:10模拟器:[11604]:警告:android/android emu/android/base/async/AsyncSocketServer.cpp:99:接受主机连接时出错错误消息:未知错误下午4:11仿真器:glTexImage2D:获取错误前:(0x502内部0x1906格式0x1906类型0x1401您在onclicklistener上有一个NPE。显示您的代码。您正在将onclicklistener设置为一个不存在的视图。设置正常,我不知道为什么