gpt4 book ai didi

java - 没有找到适合 startActivity(intent) 方法的方法

转载 作者:行者123 更新时间:2023-12-01 09:50:11 24 4
gpt4 key购买 nike

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

Error:(123, 17) error: no suitable method found for startActivities(Intent) method Context.startActivities(Intent[]) is not applicable (argument mismatch; Intent cannot be converted to Intent[]) method ContextWrapper.startActivities(Intent[]) is not applicable (argument mismatch; Intent cannot be converted to Intent[]) method Activity.startActivities(Intent[]) is not applicable (argument mismatch; Intent cannot be converted to Intent[]) package 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);

}*/
}

最佳答案

替换(在 onOptionsItemSelected 方法中):

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

与:

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

关于java - 没有找到适合 startActivity(intent) 方法的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37643534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com