Android的 - 你曾经有片段添加到清单片段、清单、Android

由网友(囚栀、)分享简介:即时通讯使用的是应该显示的WebView的片段。当我尝试从使用它,我得到我的logcat以下警告类的实例吧。02-21 23:26:46.843:W / System.err的(32468):android.content.ActivityNotFoundException:无法找到明确的活动类{get.scanner...

即时通讯使用的是应该显示的WebView的片段。当我尝试从使用它,我得到我的logcat以下警告类的实例吧。

  02-21 23:26:46.843:W / System.err的(32468):android.content.ActivityNotFoundException:无法找到明确的活动类{get.scanner / get.scanner .WebFrag};有你宣布你的Andr​​oidManifest.xml这个活动?
 

我只是学习如何使用碎片,我从来没有尝试过,宣布他们在我的表现,我还没有看到任何地方,告诉你这样做。

继承人的WebFrag类。

 公共类WebFrag扩展片段{
私人的WebView观众= NULL;

//如果我们不是只使用compat的图书馆,我们可以用WebViewFragment

@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
        捆绑savedInstanceState){
    观众=(web视图)充气
            .inflate(R.layout.webview,集装箱,假);
    WebSettings设置= viewer.getSettings();
    settings.setJavaScriptEnabled(真正的);
    settings.setDefaultZoom(ZoomDensity.FAR);

    返回浏览器;
 }

 @覆盖
 公共无效的onPause(){
   如果(观众!= NULL){
       viewer.onPause();
   }
   super.onPause();
 }

 @覆盖
 公共无效onResume(){
    super.onResume();
    如果(观众!= NULL){
        viewer.onResume();
    }
 }

 公共无效器updateURL(字符串的newURL){
    如果(观众!= NULL){
        viewer.loadUrl(的newURL);
    }
}
}
 

编辑:添加WebFrag作为活动清单导致以下错误

  02-22 00:17:55.711:E / AndroidRuntime(2524):java.lang.RuntimeException的:无法实例活动ComponentInfo {get.scanner / get.scanner.WebFrag} :java.lang.ClassCastException:get.scanner.WebFrag
 
adt bundle windows x86 64 20130917中怎么没有AndroidProject 而且Android SDK manager,install 是

编辑:继承人的主要fragmentactivity在那里我试着用我的班

 公共类GetScannerActivity扩展FragmentActivity {

私人字符串mUrl =htt​​p://www.yahoo.com/;

按钮scanButton;
按钮漆;
按钮compTrans;
字符串yurl =htt​​p://www.yahoo.com/;

@覆盖
  公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    compTrans =(按钮)findViewById(R.id.checkCurrentDeals);
    compTrans.setOnClickListener(新OnClickListener(){

        @覆盖
        公共无效的onClick(查看为arg0){
            // TODO自动生成方法存根
    WebFrag观众=(WebFrag)getSupportFragmentManager()
            .findFragmentById(R.id.web_frag);

    尝试{
    如果(观众== NULL ||!viewer.isInLayout()){
        意图showContent =新的意图(getApplicationContext()
                WebFrag.class);
        showContent.setData(Uri.parse(yurl));
        尝试{
        startActivity(showContent);
        }赶上(ActivityNotFoundException E){
            e.printStackTrace();
        }
    } 其他 {
        viewer.updateUrl(yurl);
    }
    }赶上(例外五){
        e.printStackTrace();
    }


    }
    });
 }
}
 

解决方案

没有不将其添加到您的清单。你永远需要的片段添加到您的清单。

你的地方创建一个Intent启动WebActivity?它是如何被带到屏幕上,这可能是在您的问题所在。

修改的

这是你的问题:

 意图showContent =新的意向书(getApplicationContext()
            WebFrag.class);
 startActivity(showContent);
 

您不能启动一个片段作为一个活动,你就必须包装在扩展FragmentActivity

Im using a fragment that is supposed to display a webview. When I try to instantiate it from the class that uses it I get the following warning in my logcat.

02-21 23:26:46.843: W/System.err(32468): android.content.ActivityNotFoundException: Unable   to find explicit activity class {get.scanner/get.scanner.WebFrag}; have you declared this activity in your AndroidManifest.xml?

Im just learning how to use fragments and Ive never tried declaring them in my manifest and I havent seen anywhere telling you to do so.

Heres the WebFrag class.

public class WebFrag extends Fragment{
private WebView viewer = null;

// if we weren't just using the compat library, we could use WebViewFragment

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    viewer = (WebView) inflater
            .inflate(R.layout.webview, container, false);
    WebSettings settings = viewer.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDefaultZoom(ZoomDensity.FAR);

    return viewer;
 }

 @Override
 public void onPause() {
   if (viewer != null) {
       viewer.onPause();
   }
   super.onPause();
 }

 @Override
 public void onResume() {
    super.onResume();
    if (viewer != null) {
        viewer.onResume();
    }
 }

 public void updateUrl(String newUrl) {
    if (viewer != null) {
        viewer.loadUrl(newUrl);
    }
}
}

EDIT: adding WebFrag as an activity to the manifest causes the following error

02-22 00:17:55.711: E/AndroidRuntime(2524): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{get.scanner/get.scanner.WebFrag}: java.lang.ClassCastException: get.scanner.WebFrag

EDIT: Heres the main fragmentactivity where Im trying to use my class

public class GetScannerActivity extends FragmentActivity {

private String mUrl = "http://www.yahoo.com/";

Button scanButton;
Button paint;
Button compTrans;
String yurl = "http://www.yahoo.com/";

@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    compTrans = (Button) findViewById(R.id.checkCurrentDeals);
    compTrans.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
    WebFrag viewer = (WebFrag) getSupportFragmentManager()
            .findFragmentById(R.id.web_frag);

    try{
    if (viewer == null || !viewer.isInLayout()) {
        Intent showContent = new Intent(getApplicationContext(),
                WebFrag.class);
        showContent.setData(Uri.parse(yurl));
        try{
        startActivity(showContent);
        }catch(ActivityNotFoundException e){
            e.printStackTrace();
        }
    } else {
        viewer.updateUrl(yurl);
    }   
    }catch(Exception e){
        e.printStackTrace();
    }


    }
    });
 }
}

解决方案

No don't add it to your manifest. You never need to add fragments to your manifest.

Do you create an Intent somewhere to start the WebActivity? How is it brought to the screen, that is probably where your problem lies.

EDIT

This is your problem:

 Intent showContent = new Intent(getApplicationContext(),
            WebFrag.class);
 startActivity(showContent);

You can't start a Fragment as an Activity, you'll have to wrap the fragment in an Activity that extends FragmentActivity

阅读全文

相关推荐

最新文章