问题描述
- 安卓开发中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 Layoutprivate LocalActivityManager localActivityManager = null;private LinearLayout mainTabContainer = null;private Intent mainTabIntent = null;// Tab banner titleprivate TextView mainTabTitleTextView = null;// Tab ImageViewprivate ImageView appreciateImageView = null;private ImageView discussImageView = null;private ImageView identificationImageView = null;@Overrideprotected 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());}
解决方案
跟我一样的 我也是这个状况 demo好的很
时间: 2025-01-31 01:50:12