Android Studio-无法解析方法';添加(int,com.*.WeatherFragment)和#x27;
我正在创建一个天气应用程序,收到一条错误消息 以下是我的主要活动:Android Studio-无法解析方法';添加(int,com.*.WeatherFragment)和#x27;,android,android-studio,Android,Android Studio,我正在创建一个天气应用程序,收到一条错误消息 以下是我的主要活动: package com.haziqhussain.hazweather; import android.support.v7.app.ActionBarActivity; import android.text.InputType; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle
package com.haziqhussain.hazweather;
import android.support.v7.app.ActionBarActivity;
import android.text.InputType;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
public class WeatherActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_weather);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new WeatherFragment())
.commit();
}
}
@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.
/*int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);*/
if(item.getItemId() == R.id.change_city){
showInputDialog();
}
return false;
}
private void showInputDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Change city");
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
builder.setView(input);
builder.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changeCity(input.getText().toString());
}
});
builder.show();
}
public void changeCity(String city){
WeatherFragment wf = (WeatherFragment).getSupportFragmentManager()
.findFragmentById(R.id.container);
wf.changeCity(city);
new CityPreference(this).setCity(city);
}
}
请有人帮忙,问题是onCreate部分,.add导致错误,无法解析容器。最有可能的是,
WeatherFragment
继承自android.app.Fragment
。在WeatherActivity
中,您正在使用片段的后端口(例如,getSupportFragmentManager()
)。这意味着WeatherFragment
必须扩展android.support.v4.app.Fragment
,WeatherFragment
很可能继承自android.app.Fragment
。在WeatherActivity
中,您正在使用片段的后端口(例如,getSupportFragmentManager()
)。这意味着WeatherFragment
必须扩展android.support.v4.app.Fragment
,WeatherFragment
很可能继承自android.app.Fragment
。在WeatherActivity
中,您正在使用片段的后端口(例如,getSupportFragmentManager()
)。这意味着WeatherFragment
必须扩展android.support.v4.app.Fragment
,WeatherFragment
很可能继承自android.app.Fragment
。在WeatherActivity
中,您正在使用片段的后端口(例如,getSupportFragmentManager()
)。这意味着WeatherFragment
必须扩展android.support.v4.app.Fragment
请发布您的WeatherFragment
类。@NomanRafique:Commonware的答案是正确的。导入android.support.v4.app.Fragment
而不是android.app.Fragment
。请发布您的WeatherFragment
类。@NomanRafique这里是:Commonware的答案是正确的。导入android.support.v4.app.Fragment
而不是android.app.Fragment
。请发布您的WeatherFragment
类。@NomanRafique这里是:Commonware的答案是正确的。导入android.support.v4.app.Fragment
而不是android.app.Fragment
。请发布您的WeatherFragment
类。@NomanRafique这里是:Commonware的答案是正确的。导入android.support.v4.app.Fragment
而不是android.app.Fragment
。