1
當我運行下面的代碼時,我看到「不幸撥號程序已停止工作」。爲什麼我會收到「不幸撥號程序已停止工作」?
這裏是我的代碼片段:
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)
{
}
}
});
}
}
main.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>
string.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>
爲什麼會變成這樣發生了什麼?
您是否在您的應用中添加了呼叫權限?在將問題發佈到任何論壇之前,請做一些研究(https://www.google.com.pk/search?q=android+unfortunatly+application+has+stopped)。 :) –
是的,我添加的呼叫許可CALL_PHON –
按鈕將資本 <按鈕機器人:ID = 「@ + ID/callButton」 的android:layout_width = 「FILL_PARENT」 機器人:layout_height = 「WRAP_CONTENT」 機器人:文字=」 ShowDialer「 android:background =」#d3d3d3「> 在此處輸入代碼 –