2016-03-05 15 views
1

我創建了一個頁面,顯示我的應用程序的問題。我使用了滾動文本視圖,當我加載模擬器時出現一條錯誤消息,說「不幸的是myapp」已停止工作「。該頁面已被添加到清單。 預先感謝您。當我加載模擬器時,它崩潰,並說「不幸的是myapp」已停止工作「

代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="katyloughrey5055.myapplication.QuestionsOnChapter7" 
    tools:showIn="@layout/activity_questions_on_chapter7"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Questions On Chapter 7 Differentiaion" 
     android:id="@+id/textView93" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 


    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Back" 
     android:id="@+id/Back5" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginBottom="44dp" /> 

    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/scrollView" 
     android:layout_below="@+id/textView93" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignRight="@+id/textView93" 
     android:layout_alignEnd="@+id/textView93" 
     android:layout_above="@+id/Back5"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text=" 1. A curve has equation : x² + 2xy – 3y² + 16 = 0. Find the coordinates of the points on the curve where dy/dx=0   2. A curve C is described by the equation :3x² + 4y² – 2x + 6xy – 5 = 0. Find an equation of the tangent to C at the point (1, –2).   3. A curve C is described by the equation 3x² – 2y² + 2x – 3y + 5 = 0. Find an equation of the normal to C at the point (0, 1).   4. A curve has parametric equations:x=7cost–cos7t, y= 7sint– sin7t, π/8&lt;t&lt;π/3.  (a) Find an expression for in terms of t. You need not simplify your answer.  (b) Find an equation of the normal to the curve at the point where t=π/6. Give your answer in its simplest exact form.   5. A set of curves is given by the equation sinx+cosy=0.5.  (a) Use implicit differentiation to find an expression for dy/dx  For -π&lt;x&lt;π -π&lt;y&lt;π  (b) find the coordinates of the points where dy/dx=0.   6. A curve is described by the equation x³-4y²=12xy   7. (a) Find the coordinates of the two points on the curve where x = –8.  (b) Find the gradient of the curve at each of these points.   8.A curve has equation 3x² – y² + xy = 4. The points P and Q lie on the curve. The gradient of the tangent to the curve is 83 at P and at Q .  (a) Use implicit differentiation to show that y – 2x = 0 at P and at Q.  (b) Find the coordinates of P and Q.   9.A curve C has the equation y² – 3y = x³ + 8.  (a) Find dy/dx in terms of x and y.  (b) Hence find the gradient of C at the point where y=3.   10.A curve is described by the equation x² + 4xy + y² + 27 = 0  (a) Find dy/dx in terms of x and y. A point Q lies on the curve. The tangent to the curve at Q is parallel to the y-axis.Given that the x coordinate of Q is negative, (b) use your answer to part (a) to find the coordinates of Q.&quot;" 
      android:id="@+id/textView5" /> 
    </ScrollView> 


</RelativeLayout> 

的logcat:

03-05 08:36:23.098 1921-1935/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xacbcc8d0 
       03-05 08:36:23.185 243-269/? I/ActivityManager: Displayed katyloughrey5055.myapplication/.QuizOnChapter7: +1s221ms 
       03-05 08:37:03.573 1921-1935/? W/EGL_emulation: eglSurfaceAttrib not implemented 
       03-05 08:37:03.574 1921-1935/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa44f2280, error=EGL_SUCCESS 
       03-05 08:37:03.781 1921-1935/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xacbcc2b0 
       03-05 08:37:05.765 243-548/? I/ActivityManager: START u0 {cmp=katyloughrey5055.myapplication/.QuestionsOnChapter7} from uid 10061 on display 0 
       03-05 08:37:06.898 1921-1921/? D/AndroidRuntime: Shutting down VM 
       03-05 08:37:06.907 1921-1921/? E/AndroidRuntime: FATAL EXCEPTION: main 
                 Process: katyloughrey5055.myapplication, PID: 1921 
                 java.lang.RuntimeException: Unable to start activity ComponentInfo{katyloughrey5055.myapplication/katyloughrey5055.myapplication.QuestionsOnChapter7}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 
                  at katyloughrey5055.myapplication.QuestionsOnChapter7.onCreate(QuestionsOnChapter7.java:19) 
                  at android.app.Activity.performCreate(Activity.java:6237) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  
                  at android.app.ActivityThread.-wrap11(ActivityThread.java)  
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  
                  at android.os.Handler.dispatchMessage(Handler.java:102)  
                  at android.os.Looper.loop(Looper.java:148)  
                  at android.app.ActivityThread.main(ActivityThread.java:5417)  
                  at java.lang.reflect.Method.invoke(Native Method)  
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
       03-05 08:37:06.935 243-354/? W/ActivityManager: Force finishing activity katyloughrey5055.myapplication/.QuestionsOnChapter7 
     03-05 08:37:07.041 243-354/? W/ActivityManager: Force finishing activity katyloughrey5055.myapplication/.Chapter7 
     03-05 08:37:07.097 243-261/? W/art: Long monitor contention event with owner method=void com.android.server.am.ActivityManagerService.crashApplication(com.android.server.am.ProcessRecord, android.app.ApplicationErrorReport$CrashInfo) from ActivityManagerService.java:12502 waiters=0 for 160ms 
     03-05 08:37:07.404 243-709/? I/OpenGLRenderer: Initialized EGL, version 1.4 
     03-05 08:37:07.434 243-709/? W/EGL_emulation: eglSurfaceAttrib not implemented 
     03-05 08:37:07.434 243-709/? W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa15b4060, error=EGL_SUCCESS 
     03-05 08:37:07.542 243-261/? W/ActivityManager: Activity pause timeout for ActivityRecord{51ae1ae u0 katyloughrey5055.myapplication/.QuestionsOnChapter7 t550 f} 
     03-05 08:37:15.843 243-261/? W/ActivityManager: Launch timeout has expired, giving up wake lock! 
     03-05 08:37:17.097 243-261/? W/ActivityManager: Activity destroy timeout for ActivityRecord{4286281 u0 katyloughrey5055.myapplication/.Chapter7 t550 f} 
     03-05 08:37:25.986 243-261/? W/ActivityManager: Activity destroy timeout for ActivityRecord{51ae1ae u0 katyloughrey5055.myapplication/.QuestionsOnChapter7 t550 f} 
     03-05 08:38:02.063 1921-1921/? I/Process: Sending signal. PID: 1921 SIG: 9 
     03-05 08:38:02.139 243-709/? E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa0a93c90 
     03-05 08:38:02.146 243-709/? D/OpenGLRenderer: endAllStagingAnimators on 0xa11f2c00 (RippleDrawable) with handle 0x9e2fec10 
     03-05 08:38:02.249 243-715/? D/GraphicsStats: Buffer count: 3 
     03-05 08:38:02.251 243-715/? I/WindowState: WIN DEATH: Window{31d21d1 u0 katyloughrey5055.myapplication/katyloughrey5055.myapplication.StudentPage} 
     03-05 08:38:02.369 243-548/? I/ActivityManager: Process katyloughrey5055.myapplication (pid 1921) has died 
     03-05 08:38:02.425 243-269/? W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0 
     03-05 08:38:02.742 243-548/? I/ActivityManager: Start proc 2023:katyloughrey5055.myapplication/u0a61 for activity katyloughrey5055.myapplication/.StudentPage 
     03-05 08:38:02.820 2023-2023/? I/art: Not late-enabling -Xcheck:jni (already on) 
     03-05 08:38:02.821 2023-2023/? I/art: Late-enabling JIT 
     03-05 08:38:02.973 2023-2023/? I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000 
     03-05 08:38:03.497 2023-2023/? W/System: ClassLoader referenced unknown path: /data/app/katyloughrey5055.myapplication-1/lib/arm 
     03-05 08:38:04.120 59-275/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 
+0

顯示Java文件代碼,錯誤是在你的java文件 –

+0

的問題是與按鈕,您要添加上點擊一個按鈕監聽器,而無需創建它的對象。首先,創建一個按鈕對象。 – zeeali

回答

2

您可能是試圖讓Back5一個錯誤的ID,然後分配OnClickListener還是從獲取按鈕之前,務必分配OnClickListener視圖。

0

顯然,這是一個空指針異常那裏,在你的活動,請檢查你想設置OnClickListener對象不爲空, 例如:

 
    Button b; 
     . 
     . 
     . 
     @Override 
     public void onCreate(.... 
     . 
     . 
     //whatever code you have here to initialize b 
     if(b != null){ 
     b.setOnClickListener(.... 
     //whatever you want to do with it. 
     }else{ 
      //retry to initialize b or log an error here 
      } 
    
你也應該記住這一長串的其他地方,而比佈局文件 不確定關於 getSlotFromBufferLocked的那兩條錯誤消息。 我想你應該保留在 res/raw或資產文件夾中的長文本,這將是更好的方式。

1

它是一個空指針異常,它意味着錯誤是在你的java代碼中。您要麼使用錯誤的ID獲取Back5按鈕,要麼在分配按鈕ID之前調用點擊偵聽器方法。

Button back=(Button)findVIewById(R.id.Back5); 
back.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     //your code 
    } 
    }); 
相關問題