0

I have written an android program to learn about intents.I have made the man.Xml with all needed buttons and it compiles fine. But when I load it into the emulator it crashes (Force quit).What is the reason?Also when I comments intentt2activity constructor as shown in the code,it displays the buttons.

package com.intent2;

import com.intent2.R;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class Intent2Activity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }



 /* public Intent2Activity(View view) {

     /*Intent intent;
    switch (view.getId()) {
    case R.id.Button01:
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://www.vogella.de"));
        //startActivity(intent);
        break;
    case R.id.Button02:
        intent = new Intent(Intent.ACTION_CALL,
                Uri.parse("tel:(+49)12345789"));
        //startActivity(intent);
        break;
    case R.id.Button03:
        intent = new Intent(Intent.ACTION_DIAL,
                Uri.parse("tel:(+49)12345789"));
        //startActivity(intent);
        break;
    case R.id.Button04:
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("geo:50.123,7.1434?z=19"));
        //startActivity(intent);
        break;
    case R.id.Button05:
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("geo:0,0?q=query"));
        //startActivity(intent);
        break;
    case R.id.Button06:
         intent = new Intent("android.media.action.IMAGE_CAPTURE");
        //startActivityForResult(intent, 0);
        break;
    case R.id.Button07:
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/"));
        //startActivity(intent);
        break;
    case R.id.Button08:
        intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/1"));
        //startActivity(intent);
        break;
    default:
        break;
    }
}*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (resultCode == Activity.RESULT_OK && requestCode == 0) {
    String result = data.toURI();
    Toast.makeText(this, result, Toast.LENGTH_LONG);
  }
}      

}

Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
Kannan
  • 1

3 Answers3

0

If you look at the device/emulator log it will tell you what kind of exception caused the force close (and the stack trace should point you to the exact line that is responsible).

To view the log, run the following command from the command line:

adb -e logcat

Based on what you've told us, I suspect there is an exception parsing one of the URIs.

Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
  • I gave it,But it says that windows cannot find adb – Kannan Aug 16 '11 at 00:20
  • @Kannan You should also be able to view the logcat output from your IDE (for Eclipse see http://stackoverflow.com/questions/3280051). If not, `adb` is in the `platform-tools` directory of the Android SDK. – Dan Dyer Aug 16 '11 at 00:27
0

Your data variable is probably null.

Amandeep Grewal
  • 1,801
  • 3
  • 19
  • 30
0

Intent2Activity Constructor is called before onCreate method, so when you calls it, the content still null consider that. and you must use Listeners with views -->onItemClickListener

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77