Android应用上了一个新的活动启动ForceCloses [英] Android App ForceCloses on Starting of a new activity

查看:108
本文介绍了Android应用上了一个新的活动启动ForceCloses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新android开发,我一直有强制关闭新的Andr​​oid活动页面的问题。

我的结构是这样的:

首页 - >菜单页(正常工作) - >新游戏画面(强制关闭)

呼叫的活动:

 公共无效btnNewGame_Click(查看视图)
{
    意图I =新意图(这一点,NewGameScreen.class);
    startActivityForResult(ⅰ,ACTIVITY_CREATE);
}

清单

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

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
    机器人:方向=垂直>    < ExpandableListView
        机器人:ID =@ + ID / eLVGameList
        机器人:layout_width =match_parent
        机器人:layout_gravity =center_vertical
        机器人:layout_weight =75
        机器人:背景=@空机器人:layout_height =0dip>    < / ExpandableListView>< / LinearLayout中>

NewGameScreenActivity

 保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.loadgame);
   ExpandableListView epView =(ExpandableListView)findViewById(R.id.eLVGameList);
   ExpandableListAdapter mAdapter =新GameListAdapter();
   epView.setAdapter(mAdapter);

错误:

  03-05 20:16:57.375:E / AndroidRuntime(887):致命异常:主要
03-05 20:16:57.375:E / AndroidRuntime(887):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.helloandroid / com.example.helloandroid.NewGameScreen}了java.lang.RuntimeException:您的内容必须有一个ExpandableListView的id属性是'android.R.id.list
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.os.Looper.loop(Looper.java:137)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 20:16:57.375:E / AndroidRuntime(887):在java.lang.reflect.Method.invokeNative(本机方法)
03-05 20:16:57.375:E / AndroidRuntime(887):在java.lang.reflect.Method.invoke(Method.java:511)
03-05 20:16:57.375:E / AndroidRuntime(887):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 20:16:57.375:E / AndroidRuntime(887):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 20:16:57.375:E / AndroidRuntime(887):在dalvik.system.NativeStart.main(本机方法)
03-05 20:16:57.375:E / AndroidRuntime(887):了java.lang.RuntimeException::你的内容必须有一个ExpandableListView的id属性是'android.R.id.list产生的原因
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ExpandableListActivity.onContentChanged(ExpandableListActivity.java:222)
03-05 20:16:57.375:E / AndroidRuntime(887):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.Activity.setContentView(Activity.java:1835)
03-05 20:16:57.375:E / AndroidRuntime(887):在com.example.helloandroid.NewGameScreen.onCreate(NewGameScreen.java:22)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.Activity.performCreate(Activity.java:4465)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 20:16:57.375:E / AndroidRuntime(887):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 20:16:57.375:E / AndroidRuntime(887):11 ...更多


解决方案

与此更改ExpandableListView ID

 机器人:ID =@机器人:ID /列表

如果你的类扩展活动,然后将其更改为

 公共className类扩展ListActivity

和则可以通过调用方法让你的ExpandableListView

  ExpandableListView的ListView = getListView();

I am new to android development and I have been having issues with Force Close on new Android Activity Pages.

My Structure is like this:

Main Page -> Menu Page (Works Fine) -> New Game Screen(force closes)

Call to the Activity:

    public void btnNewGame_Click(View view)
{
    Intent i = new Intent(this, NewGameScreen.class);
    startActivityForResult(i, ACTIVITY_CREATE);
}

Manifest

        <activity  android:name=".NewGameScreen"
                android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

XML

<?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:orientation="vertical" >



    <ExpandableListView
        android:id="@+id/eLVGameList"
        android:layout_width="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight=".75"
        android:background="@null" android:layout_height="0dip">

    </ExpandableListView>

</LinearLayout>

NewGameScreenActivity

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loadgame);


   ExpandableListView epView = (ExpandableListView) findViewById(R.id.eLVGameList);
   ExpandableListAdapter mAdapter = new GameListAdapter();
   epView.setAdapter(mAdapter);

Errors:

03-05 20:16:57.375: E/AndroidRuntime(887): FATAL EXCEPTION: main
03-05 20:16:57.375: E/AndroidRuntime(887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.NewGameScreen}: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.os.Looper.loop(Looper.java:137)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.main(ActivityThread.java:4424)
03-05 20:16:57.375: E/AndroidRuntime(887):  at java.lang.reflect.Method.invokeNative(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887):  at java.lang.reflect.Method.invoke(Method.java:511)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 20:16:57.375: E/AndroidRuntime(887):  at dalvik.system.NativeStart.main(Native Method)
03-05 20:16:57.375: E/AndroidRuntime(887): Caused by: java.lang.RuntimeException: Your content must have a ExpandableListView whose id attribute is 'android.R.id.list'
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ExpandableListActivity.onContentChanged(ExpandableListActivity.java:222)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Activity.setContentView(Activity.java:1835)
03-05 20:16:57.375: E/AndroidRuntime(887):  at com.example.helloandroid.NewGameScreen.onCreate(NewGameScreen.java:22)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Activity.performCreate(Activity.java:4465)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-05 20:16:57.375: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-05 20:16:57.375: E/AndroidRuntime(887):  ... 11 more

解决方案

Change your ExpandableListView id with this

android:id="@android:id/list"

and if your class extends Activity then change it to

public class className extends ListActivity

and you can get your ExpandableListView by calling the method

ExpandableListView listView = getListView();

这篇关于Android应用上了一个新的活动启动ForceCloses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆