当我尝试打开活动时,为什么app会停止

时间:2014-08-14 08:05:32

标签: android

我正在开发具有通话功能的紧急联系人应用程序,但是当尝试打开设置以输入联系人号码时,我的应用程序停止工作。 可能是什么问题呢。这是我的主要活动。

private static final int READ_BLOCK_SIZE = 100;
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.emerg_dial);

    Button callEmerg = (Button) findViewById(R.id.emerg_contact);
    callEmerg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
         Intent callIntent = new Intent(Intent.ACTION_CALL);
         callIntent.setData(Uri.parse("tel:" + ("file1")));
         startActivity(callIntent);

        }
    });

    Button callPolice = (Button) findViewById(R.id.police);
    callPolice.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
         Intent callIntent = new Intent(Intent.ACTION_CALL);
         callIntent.setData(Uri.parse("tel:" + ("file2")));
         startActivity(callIntent);

        }
    });

    Button callFire = (Button) findViewById(R.id.fire);
    callFire.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
         Intent callIntent = new Intent(Intent.ACTION_CALL);
         callIntent.setData(Uri.parse("tel:" + ("file3")));
         startActivity(callIntent);

        }
    });

    Button callDoc = (Button) findViewById(R.id.doctor);
    callDoc.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
         Intent callIntent = new Intent(Intent.ACTION_CALL);
         callIntent.setData(Uri.parse("tel:" + ("file5")));
         startActivity(callIntent);

        }
    });

    Button callHosp = (Button) findViewById(R.id.hosp);
    callHosp.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
         Intent callIntent = new Intent(Intent.ACTION_CALL);
         callIntent.setData(Uri.parse("tel:" + ("file5")));
         startActivity(callIntent);

        }
    });

    Button setButton = (Button) findViewById(R.id.set_dial);
    setButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
                      Intent intent = 
                      new Intent("com.example.emergencycontacts.Save_dials");
          startActivity(intent);
        }
});
}

        public String read_file(String file) {
         String s = "";
         try{
           FileInputStream fIn = openFileInput(file);
           InputStreamReader isr = new InputStreamReader(fIn);
           char[] inputBuffer = new char[100];

        int charRead;
         while ((charRead = isr.read(inputBuffer))>0){
        //---convert the chars to a String---
            String readString =
            String.copyValueOf(inputBuffer, 0,
            charRead);
            s += readString;
            inputBuffer = new char[100];
            }
            return s;
            }
            catch (IOException ioe) {
                ioe.printStackTrace();
            }
            return s;

        }

    //monitor phone call activities
    @SuppressWarnings("unused")
    private class PhoneCallListener extends PhoneStateListener {

        private boolean isPhoneCalling = false;

        String LOG_TAG = "LOGGING 123";

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if (TelephonyManager.CALL_STATE_RINGING == state) {
                // phone ringing
                Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            }

            if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
                // active
                Log.i(LOG_TAG, "OFFHOOK");

                isPhoneCalling = true;
            }

            if (TelephonyManager.CALL_STATE_IDLE == state) {
                // run when class initial and phone call ended, 
                // need detect flag from CALL_STATE_OFFHOOK
                Log.i(LOG_TAG, "IDLE");

                if (isPhoneCalling) {

                    Log.i(LOG_TAG, "restart app");

                    // restart app
                    Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                            getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);

                    isPhoneCalling = false;
                }

            }
        }
    }

 }

这是清单代码:

        android:name="com.example.emergencycontacts.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.emergencycontacts.Set_dials"
        android:label="@string/app_name" >
        <intent-filter>
          <action android:name="android.intent.action.MAIN" />

          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
   </activity>
   <activity android:name=".Save_dials"
    android:label="@string/app_name">
    <intent-filter>
      <action  android:name="com.example.emergencycontacts.Save_dials" />

         <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
   </activity>

1 个答案:

答案 0 :(得分:0)

更改

Intent intent = new Intent("com.example.emergencycontacts.Save_dials");

Intent intent = new Intent(MainActivity.this,Save_dials.class);
<{1}} onClick

中的