您好,现在开始在 Android 中构建小型应用程序。我尝试通过调用 Call Intent 来启动按钮单击呼叫。我已经在 Manifest 文件中设置了必要的权限。
但我仍然收到错误消息
com.android.phone 停止工作
<Linear Layout
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:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnShow"
android:text="@string/btnShow"
android:fontFamily="sans-serif" />
</LinearLayout>
MainActivity.java
package com.example.androidproject2;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnShowDialer=(Button) findViewById(R.id.btnShow);
btnShowDialer.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0) {
try
{ Intent callIntent=new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:1121121212"));
startActivity(callIntent);
}
catch(Exception e)
{
Log.e("Trail","Call Falied", e);
}
}
});
}
}
日志输出
08-08 09:29:28.378: D/gralloc_goldfish(862): Emulator without GPU emulation detected.
08-08 09:29:37.548: D/AndroidRuntime(862): Shutting down VM
08-08 09:29:37.608: W/dalvikvm(862): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-08 09:29:37.688: E/AndroidRuntime(862): FATAL EXCEPTION: main
08-08 09:29:37.688: E/AndroidRuntime(862): java.lang.IllegalStateException: Could not find a method showDialer(View) in the activity class com.example.androidproject2.MainActivity for onClick handler on view class android.widget.Button with id 'btnShow'
08-08 09:29:37.688: E/AndroidRuntime(862): at android.view.View$1.onClick(View.java:3620)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.view.View.performClick(View.java:4240)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.view.View$PerformClick.run(View.java:17721)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.os.Handler.handleCallback(Handler.java:730)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.os.Handler.dispatchMessage(Handler.java:92)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.os.Looper.loop(Looper.java:137)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-08 09:29:37.688: E/AndroidRuntime(862): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 09:29:37.688: E/AndroidRuntime(862): at java.lang.reflect.Method.invoke(Method.java:525)
08-08 09:29:37.688: E/AndroidRuntime(862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-08 09:29:37.688: E/AndroidRuntime(862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-08 09:29:37.688: E/AndroidRuntime(862): at dalvik.system.NativeStart.main(Native Method)
08-08 09:29:37.688: E/AndroidRuntime(862): Caused by: java.lang.NoSuchMethodException: showDialer [class android.view.View]
08-08 09:29:37.688: E/AndroidRuntime(862): at java.lang.Class.getConstructorOrMethod(Class.java:423)
08-08 09:29:37.688: E/AndroidRuntime(862): at java.lang.Class.getMethod(Class.java:787)
08-08 09:29:37.688: E/AndroidRuntime(862): at android.view.View$1.onClick(View.java:3613)
08-08 09:29:37.688: E/AndroidRuntime(862): ... 11 more
08-08 09:39:06.209: D/gralloc_goldfish(931): Emulator without GPU emulation detected.
08-08 09:39:23.398: I/Choreographer(931): Skipped 82 frames! The application may be doing too much work on its main thread.
08-08 09:39:26.398: I/Choreographer(931): Skipped 110 frames! The application may be doing too much work on its main thread.