强制关闭在Android应用 [英] Force close in android app

查看:186
本文介绍了强制关闭在Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在我的code错误,但施加力在启动本身关闭。以下是code。

There is no error in my code but the application force closes at the start itself. Following is the code.

package com.amit.wozzle;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
private Button b1;
private Button b2;
private Button b3;
private Button b4;
private Button b5;
private Button b6;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b1 = (Button) findViewById(R.id.g1);
    b2 = (Button) findViewById(R.id.g2);
    b3 = (Button) findViewById(R.id.g3);
    b4 = (Button) findViewById(R.id.g4);
    b5 = (Button) findViewById(R.id.g5);
    b6 = (Button) findViewById(R.id.g6);


    b1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 1);
            startActivity(r1);
        }
    });


    b2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 2);
            startActivity(r1);
        }
    });


    b3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 3);
            startActivity(r1);
        }
    });


    b4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 4);
            startActivity(r1);
        }
    });


    b5.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 5);
            startActivity(r1);
        }
    });


    b6.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent r1= new Intent("com.amit.wozzle.GAMEPLAY");
            r1.putExtra("choice", 6);
            startActivity(r1);
        }
    });




}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

这是logcat的。

07-15 12:57:37.632: D/AndroidRuntime(666): Shutting down VM
07-15 12:57:37.632: W/dalvikvm(666): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-15 12:57:37.642: E/AndroidRuntime(666): FATAL EXCEPTION: main
07-15 12:57:37.642: E/AndroidRuntime(666): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amit.wozzle/com.amit.wozzle.MainActivity}:    java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in    AdapterView
07-15 12:57:37.642: E/AndroidRuntime(666):  at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-15 12:57:37.642: E/AndroidRuntime(666):  at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.os.Looper.loop(Looper.java:123)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-15 12:57:37.642: E/AndroidRuntime(666):  at java.lang.reflect.Method.invokeNative(Native Method)
07-15 12:57:37.642: E/AndroidRuntime(666):  at java.lang.reflect.Method.invoke(Method.java:521)
07-15 12:57:37.642: E/AndroidRuntime(666):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-15 12:57:37.642: E/AndroidRuntime(666):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-15 12:57:37.642: E/AndroidRuntime(666):  at dalvik.system.NativeStart.main(Native Method)
07-15 12:57:37.642: E/AndroidRuntime(666): Caused by: java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.widget.AdapterView.addView(AdapterView.java:461)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:622)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-15 12:57:37.642: E/AndroidRuntime(666):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.Activity.setContentView(Activity.java:1647)
07-15 12:57:37.642: E/AndroidRuntime(666):  at com.amit.wozzle.MainActivity.onCreate(MainActivity.java:23)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-15 12:57:37.642: E/AndroidRuntime(666):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-15 12:57:37.642: E/AndroidRuntime(666):  ... 11 more

有谁请告诉什么错误呢?

Could anybody please tell what error is there ?

推荐答案

我觉得这是在你的code错误。 4号线就指出:addview不支持适配器视图。看起来是表示你应该包装,在一个try / catch块,赶上这个错误,这样它不会强制关闭您的应用程序,或者你需要弄清楚为什么addView不与适配器视图支持。
此外,从该行,上面写着致,你可以看到错误重演。

I think there is an error in your code. On the 4th line it states that "addview is not supported in adapterview." It looks like that is indicating you should wrap that in a try/catch block and catch that error so that it is not force closing your app or you need to figure out why that addView is not supported with the adapterview. Also, from that line that says "caused by" you can see the error repeated.

这篇关于强制关闭在Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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