当我运行以下代码时,我看到“不幸的是拨号器已停止工作”。
这是我的代码片段:
DialerActivity.java
package com.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.net.Uri;
import android.widget.Button;
import android.view.*;
public class DialerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button callButton=(Button) findViewById(R.id.callButton);
callButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
try {
Intent CallIntent =
new Intent(Intent.ACTION_CALL,Uri.parse("tel:9563460376"));
CallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(CallIntent);
}
catch(Exception e)
{
}
}
});
}
}
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<button android:id="@+id/callButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ShowDialer"
android:background="#d3d3d3">
</button>
</LinearLayout>
字符串.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hell">sanjoy</string>
<string name="app_name">Test</string>
<string name="button">ShowDialer</string>
</resources>
为什么会发生这种情况?