首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android -你有没有在清单中添加过片段?

android -你有没有在清单中添加过片段?
EN

Stack Overflow用户
提问于 2012-02-22 15:33:25
回答 1查看 54.7K关注 0票数 23

我正在使用一个片段,它应该显示一个网页视图。当我试图从使用它的类实例化它时,我在我的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?

我只是在学习如何使用片段,我从来没有尝试过在我的清单中声明它们,我也没有看到任何地方告诉你这样做。

下面是WebFrag类。

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);
    }
}
}

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

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

编辑:这里是我尝试使用我的类的主要片段活动

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();
    }


    }
    });
 }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9390752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档