无法解析方法Add(INT,新tFragment())。在安卓1.0.1 studion的commit()

编程入门 行业动态 更新时间:2024-10-20 05:38:15
本文介绍了无法解析方法Add(INT,新tFragment())。在安卓1.0.1 studion的commit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是用碎片的工作在Android Studio中1.0.1。正如网络的过程并不看好主UI做的,我搬到我的code含有片段不同的类。但是,以后的事情没有帮助我继续在所有。我得到的错误是无法化解的方法添加(R.id.container,新com.sunshine.example.sunshine.app.Fragment)mit(); 到这里是我的MainActivity类别的code片段,但一切都很好用片段类。

包com.sunshine.example.sunshine.app;      进口android.support.v7.app.ActionBarActivity;      进口android.support.v4.app.Fragment;      进口android.os.Bundle;      进口android.view.Menu;      进口android.view.MenuItem;      公共类MainActivity扩展ActionBarActivity {      @覆盖      保护无效的onCreate(捆绑savedInstanceState){      super.onCreate(savedInstanceState);      的setContentView(R.layout.activity_main);      如果(savedInstanceState == NULL){          getSupportFragmentManager()调用BeginTransaction()。                  加(R.id.container,新ForecastFragment())提交()。      }}      @覆盖公共布尔onCreateOptionsMenu(菜单菜单){      //充气菜单;如果是present这增加了项目操作栏。      。getMenuInflater()膨胀(R.menu.menu_main,菜单);      返回true; }      @覆盖公共布尔onOptionsItemSelected(菜单项项){      //处理动作栏项目点击这里。操作栏会      //自动处理上点击主页/向上按钮,只要      //你在AndroidManifest.xml中指定一个父活动。      INT ID = item.getItemId();      // noinspection SimplifiableIfStatement      如果(ID == R.id.action_settings){          返回true;      }      返回super.onOptionsItemSelected(项目); }      }

解决方案

编译时错误提示你的 ForecastFragment 正在使用的原生片段支持 app.Fragment ,但在你的活动,你正在使用的事务从支持库。你必须要与进口相一致。更改 ForecastFragment ,以使其从支持库中的片段

I was working with fragments in android studio 1.0.1. Just as network process are not good to be done in the main UI, i moved my code to a different class containing fragments. But what happened afterwards is not helping me proceed at all. the error i get is cannot resolve method add(R.id.container, new com.sunshine.example.sunshine.app.Fragment)mit(); down here is the code snippet of my MainActivity class but all is well with Fragment class.

package com.sunshine.example.sunshine.app; import android.support.v7.app.ActionBarActivity; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction(). add(R.id.container, new ForecastFragment())mit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, 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. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }

解决方案

the compile time error is suggesting that your ForecastFragment is using the native fragment support app.Fragment, but in your activity you are using a transaction from the support library. You have to be consistent with the import. Change your ForecastFragment in order to make it use the Fragment from the support library

更多推荐

无法解析方法Add(INT,新tFragment())。在安卓1.0.1 studion的commit()

本文发布于:2023-11-12 12:09:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   INT   Add   tFragment   studion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!