找不到startActivity(intent)方法的sutiable方法

时间:2016-06-05 15:25:39

标签: java android android-studio

显示错误,在启动活动中找不到合适的方法,错误是:

  

错误:(123,17)错误:找不到适合startActivities(Intent)方法的方法Context.startActivities(Intent [])不适用(参数不匹配; Intent无法转换为Intent [])方法ContextWrapper.startActivities (Intent [])不适用(参数不匹配; Intent无法转换为Intent [])方法Activity.startActivities(Intent [])不适用(参数不匹配; Intent无法转换为Intent [])包com.smartcodeone .newapp1;

public class MainActivity extends ListActivity{

    public static final String STRING_VAR = "com.smartcodeone.newapp1.HELLO_WORLD";
    public static final String STRING_RATE = "com.smartcodeone.newapp1.RAIING";
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    public  ListView  listView_allContacts;
    //ArrayAdapter adapter=new ArrayAdapter<String>(this,R.layout.,StringArray);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView_allContacts=getListView();
                //(ListView) findViewId(R.id.listView_allContacts);
        //listView_allContacts.setAdapter(adapter);


        Button btnMsg = (Button) findViewById(R.id.btnMsg);
         Button btnint = (Button) findViewById(R.id.btnshare);
      //  Button btnWidge   t = (Button) findViewById(R.id.btnwidget);
       // TextView etName1 = (TextView) findViewId(R.id.etName);
       // EditText etName = (EditText) findViewId(R.id.tvName);




        btnMsg.setOnClickListener(new View.OnClickListener() {

            //when user click's this function will be called
            public void onClick(View v) {
                Intent intentvar = new Intent(getApplicationContext(), Main2Activity.class);
                intentvar.putExtra(STRING_VAR, "Hello World");   //this is used to pass data to next intent
                intentvar.putExtra(STRING_RATE, 3);
                startActivity(intentvar);
            }
        });

        btnint.setOnClickListener(new View.OnClickListener() {
            //when user want to share something
            public void onClick(View v) {
                Intent intentShare = new Intent(Intent.ACTION_SEND);
                intentShare.setType("text/palin");
                intentShare.putExtra(Intent.EXTRA_TEXT, "This is invitation to all my friend to see this app");

                //ensure we have an appliction that can handle this type of data
                if (intentShare.resolveActivity(getPackageManager()) != null) {
                    startActivity(intentShare);
                }
            }
        });

        /*btnWidget.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intentwid = new Intent(getApplicationContext(), NewAppWidget.class);
                startActivity(intentwid);
            }


        });
*/

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    private int findViewId(int btnMsg) {
        return 0;

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.


        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()){
            case R.id.menu_new_contact:

               // startActivities(new Intent(MainActivity.this, ContactDetailsActivity.class));

                break;

        }

        return super.onOptionsItemSelected(item);
    }

  /*  @Override
    public FragmentManager getSupportFragmentManager() {
        return null;
    }
*/



    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "Main Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app URL is correct.
                Uri.parse("android-app://com.smartcodeone.newapp1/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "Main Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app URL is correct.
                Uri.parse("android-app://com.smartcodeone.newapp1/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }
  /*  protected void  onResume(){

        Dbhelper db =new Dbhelper(this);
        ArrayList<String>  names=new ArrayList<String>();
        for(int i=0;i<db.getAllContact().size();i++)
            names.add(db.getAllContact().get(i).getName());
        ArrayAdapter adapter =new ArrayAdapter(this,android.R.layout.simple_list_item_1,names);
        listView_allContacts.setAdapter(adapter);

    }*/
}

1 个答案:

答案 0 :(得分:1)

替换(在onOptionsItemSelected方法内):

startActivities(new Intent(MainActivity.this, ContactDetailsActivity.class));

使用:

startActivity(new Intent(MainActivity.this, ContactDetailsActivity.class));