Android Studio“Button Tapped!”

时间:2015-11-06 18:01:12

标签: android button logging android-studio

感谢您阅读此问题。

我是学习开发Android应用程序的新手,几乎没有编码经验。我正在使用以下代码的教师使用以下代码将一个添加到我们的Android Studio Project的按钮发送到日志中的消息“Button Tapped!”,以便在每次单击特定按钮时记录特定按钮单击:

public void clickfunction(View view){Log.i(“Info”, “Button Tapped!”);}

我需要两天时间才能运行安装了最新更新的运行OS X 10.11.1的iMac上的Android Studio 1.4.1启动Android模拟器。

即使这样,“Android应用程序我的应用程序测试停止了”,使用定制的Android虚拟设备(AVD)在启动的模拟器中单击按钮时出现“配置为8”DROID TURBO,带有3GB内存,1440 x 2560.至少日志显示以下错误,因此从技术上讲,“按钮工作”,因为它将以下消息发送到日志。它没有在日志中显示“Button Tapped!”:

Android监视器

11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest     E/AndroidRuntime: FATAL EXCEPTION: main
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest     E/AndroidRuntime: Process: com.example.chris.myapplicationtest, PID: 3298
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime: java.lang.IllegalStateException: Could not find method   clickfunctio(View) in a parent or ancestor Context for android:onClick   attribute defined on view class android.support.v7.widget.AppCompatButton  with id 'button'
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:310)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:269)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.view.View.performClick(View.java:5198)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:21147)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-06 11:23:39.600 3298-3298/com.example.chris.myapplicationtest E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-06 11:23:41.390 3298-3298/com.example.chris.myapplicationtest I/Process: Sending signal. PID: 3298 SIG: 9

事件日志

11:00:17 AM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
11:00:19 AM Gradle build finished with 10 error(s) in 1s 984ms
11:09:02 AM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
11:09:03 AM Gradle build finished with 2 error(s) in 1s 426ms
11:09:26 AM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
11:09:40 AM Gradle build finished in 14s 275ms
11:21:02 AM Session 'app': running
11:23:38 AM IllegalStateException: no segments available. offset = 3921
11:23:38 AM Platform and Plugin Updates: The following component is ready to update: Android Auto Desktop Head Unit emulator
11:23:46 AM IllegalStateException: no segments available. offset = 3654
11:26:26 AM Can't bind to local 8700 for debugger
11:26:28 AM Can't bind to local 8700 for debugger

再次,

感谢您的时间!

感谢那些回答的人,以及那些读过这篇文章的人。您的所有答案都与我的课程提供的指示完全相同。讨论板。谢谢大家,再次!

2 个答案:

答案 0 :(得分:1)

onClick方法名称不匹配

因为Button xml中的clickfunctio中添加了android:onClick作为方法,但代码方法名称为clickfunction

答案 1 :(得分:0)

您遇到拼写错误:在XML文件中将clickfunctio更改为clickfunction