无法启动的活动ComponentInfo

无法启动的活动ComponentInfo

本文介绍了java.lang.RuntimeException的:无法启动的活动ComponentInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道出现在次论坛上亿这个错误,但请帮我找到我错过了。我试图做简单的标签朝向的应用程序,我没有太多的(除非错误)

1)我的主要活动是基于tablayout教程中我发现了什么

 公共类MainTabPanel扩展TabActivity {

    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.mainlayout);
        资源RES = getResources();
        TabHost tabHost = getTabHost();
        TabHost.TabSpec规范;
        意向意图;
        意图=新的意图()setClass(这一点,MyBookActivity.class)。
        规格= tabHost.newTabSpec(主)
                .setIndicator(主,res.getDrawable(R.drawable.ic_mybook))
                .setContent(意向);
        tabHost.addTab(规范);
        tabHost.setCurrentTab(0);
    }

}
 

2)mainlayout.xml

 < XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:ID =@机器人:ID / tabhost
 机器人:layout_width =FILL_PARENT
 机器人:layout_height =FILL_PARENT>
 <的LinearLayout
   机器人:方向=垂直
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT
   机器人:填充=5DP>
 < TabWidget
  机器人:ID =@机器人:ID /标签
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =WRAP_CONTENT/>

  <的FrameLayout
  机器人:ID =@机器人:ID / tabcontent
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:填充=5DP/>
 < / LinearLayout中>< / TabHost>
 

3)我的第二个活动是基本上几乎是空的,它,只是显示当前的日期和时间,工作之前,我尝试添加标签面板

4)我的清单文件

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=org.th.mybook
    安卓版code =1
    机器人:VERSIONNAME =1.0>
    <使用-SDK安卓的minSdkVersion =8/>
    <应用
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME>
        <活动
            机器人:名称=。MainTabPanel
            机器人:标签=@字符串/ APP_NAME>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名称=MyBookActivity
            机器人:标签=@字符串/ APP_NAME>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.ALTERNATIVE/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>
< /舱单>
 

5日志猫误差

  02-10 21:04:45.203:E / AndroidRuntime(1107):致命异常:主要
02-10 21:04:45.203:E / AndroidRuntime(1107):java.lang.RuntimeException的:无法启动的活动ComponentInfo {org.th.mybook / org.th.mybook.MainTabPanel}:java.lang.RuntimeException的:无法实例活动ComponentInfo {org.th.mybook / org.th.mybook.MyBookActivity}:显示java.lang.NullPointerException
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.os.Handler.dispatchMessage(Handler.java:99)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.os.Looper.loop(Looper.java:123)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.main(ActivityThread.java:4627)
02-10 21:04:45.203:E / AndroidRuntime(1107):在java.lang.reflect.Method.invokeNative(本机方法)
02-10 21:04:45.203:E / AndroidRuntime(1107):在java.lang.reflect.Method.invoke(Method.java:521)
02-10 21:04:45.203:E / AndroidRuntime(1107):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
02-10 21:04:45.203:E / AndroidRuntime(1107):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-10 21:04:45.203:E / AndroidRuntime(1107):在dalvik.system.NativeStart.main(本机方法)
02-10 21:04:45.203:E / AndroidRuntime(1107):java.lang.RuntimeException的:产生的原因无法实例活动ComponentInfo {org.th.mybook / org.th.mybook.MyBookActivity}:java.lang中。空指针异常
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost.java:651)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.widget.TabHost.setCurrentTab(TabHost.java:323)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.widget.TabHost.addTab(TabHost.java:213)
02-10 21:04:45.203:E / AndroidRuntime(1107):在org.th.mybook.MainTabPanel.onCreate(MainTabPanel.java:30)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-10 21:04:45.203:E / AndroidRuntime(1107):11 ...更多
02-10 21:04:45.203:E / AndroidRuntime(1107):由:显示java.lang.NullPointerException
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
02-10 21:04:45.203:E / AndroidRuntime(1107):在org.th.mybook.MyBookActivity< INIT>(MyBookActivity.java:16)
02-10 21:04:45.203:E / AndroidRuntime(1107):在java.lang.Class.newInstanceImpl(本机方法)
02-10 21:04:45.203:E / AndroidRuntime(1107):在java.lang.Class.newInstance(Class.java:1429)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-10 21:04:45.203:E / AndroidRuntime(1107):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-10 21:04:45.203:E / AndroidRuntime(1107):20 ...更多
 

请帮帮我,告诉我什么,我错过了,即时通讯比较这code和我的老之一,我无法找到任何东西关于

6)我的书的活动

 公共类MyBookActivity延伸活动{
    java.text.DateFormat中DATEFORMAT = android.text.format.DateFormat.getDateFormat(getApplicationContext());

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        DigitalClock时钟=(DigitalClock)findViewById(R.id.digitalClock1);
        最后的TextView日期=(TextView中)findViewById(R.id.textView1);
        date.setText(dateFormat.format(新日期()));
        TextWatcher观察家=新TextWatcher(){

            @覆盖
            公共无效afterTextChanged(编辑S){
            }

            @覆盖
            公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,
                    之后INT){
            }

            @覆盖
            公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,
                    诠释计数){

                如果(s.toString()。startsWith(00:00:00)
                        || s.toString()。startsWith(12点○○分00秒)){
                    date.setText(dateFormat.format(新日期()));
                }
            }
        };
        clock.addTextChangedListener(守望者);

    }
}
 

7)main.xml中的布局 - >我的书的活动

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:重力=右
    机器人:方向=横向>


    <的LinearLayout
        机器人:ID =@ + ID / DatePanel1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT>


        <的TextView
            机器人:ID =@ + ID / textView1
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginRight =@扪/空间
            机器人:layout_weight =1
            机器人:文本=TextView的/>

        < D​​igitalClock
            机器人:ID =@ + ID / digitalClock1
            机器人:layout_width =0dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:文本=DigitalClock/>
    < / LinearLayout中>

< / LinearLayout中>
 

解决方案

 <活动
        机器人:名称=MyBookActivity
        机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.ALTERNATIVE/>
        &所述; /意图滤光器>
    < /活性GT;
 

在哪里MyBookActivity之前,你点?

I know this error appeared on forum million of times, but please help me find what I missed.I'm trying to do simple tab orientated application,I don't have much (except errors)

1) my main activity is based on tablayout tutorial what I found

public class MainTabPanel extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainlayout);
        Resources res = getResources();
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;
        intent = new Intent().setClass(this, MyBookActivity.class);
        spec = tabHost.newTabSpec("main")
                .setIndicator("Main", res.getDrawable(R.drawable.ic_mybook))
                .setContent(intent);
        tabHost.addTab(spec);
        tabHost.setCurrentTab(0);
    }

}

2) mainlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@android:id/tabhost"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <LinearLayout
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="5dp">
 <TabWidget
  android:id="@android:id/tabs"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" />

  <FrameLayout
  android:id="@android:id/tabcontent"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="5dp" />
 </LinearLayout></TabHost>

3) my second activity is basically almost empty, it;s just display current date and time, worked before I tried to add tab panel

4) my manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.th.mybook"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainTabPanel"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="MyBookActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.ALTERNATIVE" />
            </intent-filter>
        </activity>
    </application>
</manifest>

5 log cat error

02-10 21:04:45.203: E/AndroidRuntime(1107): FATAL EXCEPTION: main
02-10 21:04:45.203: E/AndroidRuntime(1107): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.th.mybook/org.th.mybook.MainTabPanel}: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.th.mybook/org.th.mybook.MyBookActivity}: java.lang.NullPointerException
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.os.Looper.loop(Looper.java:123)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at java.lang.reflect.Method.invokeNative(Native Method)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at java.lang.reflect.Method.invoke(Method.java:521)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at dalvik.system.NativeStart.main(Native Method)
02-10 21:04:45.203: E/AndroidRuntime(1107): Caused by: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.th.mybook/org.th.mybook.MyBookActivity}: java.lang.NullPointerException
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.widget.TabHost.addTab(TabHost.java:213)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at org.th.mybook.MainTabPanel.onCreate(MainTabPanel.java:30)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-10 21:04:45.203: E/AndroidRuntime(1107):     ... 11 more
02-10 21:04:45.203: E/AndroidRuntime(1107): Caused by: java.lang.NullPointerException
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at org.th.mybook.MyBookActivity.<init>(MyBookActivity.java:16)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at java.lang.Class.newInstanceImpl(Native Method)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at java.lang.Class.newInstance(Class.java:1429)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-10 21:04:45.203: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
02-10 21:04:45.203: E/AndroidRuntime(1107):     ... 20 more

please help me, and tell me what i missed, im comparing this code with my old one and i can't find anythingregards

6) my book activity

public class MyBookActivity extends Activity {
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        DigitalClock clock = (DigitalClock) findViewById(R.id.digitalClock1);
        final TextView date = (TextView) findViewById(R.id.textView1);
        date.setText(dateFormat.format(new Date()));
        TextWatcher watcher = new TextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

                if (s.toString().startsWith("00:00:00")
                        || s.toString().startsWith("12:00:00")) {
                    date.setText(dateFormat.format(new Date()));
                }
            }
        };
        clock.addTextChangedListener(watcher);

    }
}

7) main.xml layout -> for my book activity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="right"
    android:orientation="horizontal" >


    <LinearLayout
        android:id="@+id/DatePanel1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >


        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/space"
            android:layout_weight="1"
            android:text="TextView" />

        <DigitalClock
            android:id="@+id/digitalClock1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="DigitalClock" />
    </LinearLayout>

</LinearLayout>
解决方案
    <activity
        android:name="MyBookActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.ALTERNATIVE" />
        </intent-filter>
    </activity>

where is your dot before MyBookActivity?

这篇关于java.lang.RuntimeException的:无法启动的活动ComponentInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:01