2 qiuqingyu qiuqingyu 于 2014.11.08 22:23 提问

安卓开发中java.lang.RuntimeException: Unable to start activity ComponentInfo问题

package com.example.test;

import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class MainActivity extends ActivityGroup {

// Tab Activity Layout
private LocalActivityManager localActivityManager = null;
private LinearLayout mainTabContainer = null;
private Intent mainTabIntent = null;

// Tab banner title
private TextView mainTabTitleTextView = null;
// Tab ImageView
private ImageView appreciateImageView = null;
private ImageView discussImageView = null;
private ImageView identificationImageView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    appreciateImageView = (ImageView) super
            .findViewById(R.id.appreciate_tab_btn);
    mainTabContainer = (LinearLayout) findViewById(R.id.main_tab_banner_title);
    appreciateImageView.setImageResource(R.drawable.appreciate_press);
    discussImageView.setImageResource(R.drawable.discuss_normal);
    identificationImageView
            .setImageResource(R.drawable.identification_normal);
    localActivityManager = getLocalActivityManager();
    mainTabTitleTextView = (TextView) findViewById(R.id.main_tab_banner_title);
    appreciateImageView = (ImageView) findViewById(R.id.appreciate_tab_btn);
    discussImageView = (ImageView) findViewById(R.id.discuss_tab_btn);
    identificationImageView = (ImageView) findViewById(R.id.identification_tab_btn);
    setContainerView("appreciate", AppreciateTabActivity.class);
    setContentView(R.layout.activity_main);

    initTab();

}

/**
 * 初始化Tab项
 */
private void initTab() {
    mainTabTitleTextView = (TextView) findViewById(R.id.main_tab_banner_title);
    appreciateImageView = (ImageView) findViewById(R.id.appreciate_tab_btn);
    discussImageView = (ImageView) findViewById(R.id.discuss_tab_btn);
    identificationImageView = (ImageView) findViewById(R.id.identification_tab_btn);




  appreciateImageView.setOnClickListener(new OnClickListener() {

  @Override public void onClick(View v) {

  appreciateImageView .setImageResource(R.drawable.appreciate_press);
  discussImageView.setImageResource(R.drawable.discuss_normal);
  identificationImageView
  .setImageResource(R.drawable.identification_normal);

  setContainerView("appreciate", AppreciateTabActivity.class);
  mainTabTitleTextView.setText("欣赏美花");

  } });




  discussImageView.setOnClickListener(new OnClickListener() {

  @Override public void onClick(View v) {

  appreciateImageView .setImageResource(R.drawable.appreciate_normal);
 discussImageView.setImageResource(R.drawable.discuss_press);
  identificationImageView
  .setImageResource(R.drawable.identification_normal);

  setContainerView("discuss", DiscussTabActivity.class);
  mainTabTitleTextView.setText("评花论花");

  } });




  identificationImageView.setOnClickListener(new OnClickListener() {

  @Override public void onClick(View v) {

  appreciateImageView .setImageResource(R.drawable.appreciate_normal);
  discussImageView.setImageResource(R.drawable.discuss_normal);
  identificationImageView
  .setImageResource(R.drawable.identification_press);
  setContainerView("identification", IdentificationTabActivity.class);
 mainTabTitleTextView.setText("亮眼识花");

  } });

}

public void setContainerView(String id, Class<?> activity) {
    mainTabContainer.removeAllViews();
    mainTabIntent = new Intent(this, activity);
    mainTabContainer.addView(localActivityManager.startActivity(id,
            mainTabIntent).getDecorView());
}

}
出现如下错误:CSDN移动问答

1个回答

zzcjsnj
zzcjsnj   2015.04.13 20:12

跟我一样的 我也是这个状况 demo好的很

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!