无法启动活动ComponentInfo - 活动崩溃

时间:2014-02-09 10:15:01

标签: java android

加载活动时,我的应用程序会立即崩溃,并显示“无法启动活动ComponentInfo”logcat。

一旦此活动尝试运行,应用程序就会崩溃。

我的活动代码是:

package com.example.cg4project;



import android.os.Bundle;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ChildScreen extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_child_screen);



    //Gte child array size
    int arraySize = Global.getInstance().childArray.size();

    if (arraySize == 0){

    }else{//Create new button
        Button myButton = new Button(this);

        //For loop from 0 to array size
        for(int counter = 0; counter < arraySize; counter++){
            //Set button text
            myButton.setText(Global.getInstance().childArray.get(counter).aFirstName + " " + Global.getInstance().childArray.get(counter).aLastName + " Stars: " + Global.getInstance().childArray.get(counter).aPoints);
            //Create linear layout
            LinearLayout ll = (LinearLayout)findViewById(R.id.layout1);

            LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            //Add button to layout
            ll.addView(myButton, lp);

            myButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    //Open child activity
                    Intent i = new Intent(ChildScreen.this, Child.class);
                    ChildScreen.this.startActivity(i);

                }
            });

        }
    }





    final Button btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Open child create activity
            Intent i = new Intent(ChildScreen.this, ChildCreate.class);
            ChildScreen.this.startActivity(i);
        }

        });


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.child_screen, menu);
    return true;
}

}

我的logcat是。

02-09 10:07:24.626: E/AndroidRuntime(3458): FATAL EXCEPTION: main
02-09 10:07:24.626: E/AndroidRuntime(3458): Process: com.example.cg4project, PID: 3458
02-09 10:07:24.626: E/AndroidRuntime(3458): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cg4project/com.example.cg4project.ChildScreen}: java.lang.NullPointerException
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.os.Looper.loop(Looper.java:136)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at java.lang.reflect.Method.invokeNative(Native Method)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at java.lang.reflect.Method.invoke(Method.java:515)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at dalvik.system.NativeStart.main(Native Method)
02-09 10:07:24.626: E/AndroidRuntime(3458): Caused by: java.lang.NullPointerException
02-09 10:07:24.626: E/AndroidRuntime(3458):     at com.example.cg4project.ChildScreen.onCreate(ChildScreen.java:64)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.Activity.performCreate(Activity.java:5231)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-09 10:07:24.626: E/AndroidRuntime(3458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-09 10:07:24.626: E/AndroidRuntime(3458):     ... 11 more
02-09 10:12:24.816: W/System.err(3789): java.io.FileNotFoundException: /storage/emulated/0/userAccounts.txt: open failed: ENOENT (No such file or directory)
02-09 10:12:24.816: W/System.err(3789):     at libcore.io.IoBridge.open(IoBridge.java:409)
02-09 10:12:24.816: W/System.err(3789):     at java.io.FileInputStream.<init>(FileInputStream.java:78)
02-09 10:12:24.816: W/System.err(3789):     at com.example.cg4project.Login.onCreate(Login.java:29)
02-09 10:12:24.816: W/System.err(3789):     at android.app.Activity.performCreate(Activity.java:5231)
02-09 10:12:24.816: W/System.err(3789):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-09 10:12:24.816: W/System.err(3789):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-09 10:12:24.816: W/System.err(3789):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-09 10:12:24.816: W/System.err(3789):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-09 10:12:24.816: W/System.err(3789):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-09 10:12:24.816: W/System.err(3789):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-09 10:12:24.816: W/System.err(3789):     at android.os.Looper.loop(Looper.java:136)
02-09 10:12:24.816: W/System.err(3789):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-09 10:12:24.816: W/System.err(3789):     at java.lang.reflect.Method.invokeNative(Native Method)
02-09 10:12:24.816: W/System.err(3789):     at java.lang.reflect.Method.invoke(Method.java:515)
02-09 10:12:24.816: W/System.err(3789):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-09 10:12:24.816: W/System.err(3789):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-09 10:12:24.816: W/System.err(3789):     at dalvik.system.NativeStart.main(Native Method)
02-09 10:12:24.816: W/System.err(3789): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
02-09 10:12:24.816: W/System.err(3789):     at libcore.io.Posix.open(Native Method)
02-09 10:12:24.816: W/System.err(3789):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
02-09 10:12:24.816: W/System.err(3789):     at libcore.io.IoBridge.open(IoBridge.java:393)
02-09 10:12:24.816: W/System.err(3789):     ... 16 more
02-09 10:12:24.896: D/libEGL(3789): loaded /system/lib/egl/libEGL_tegra.so
02-09 10:12:24.916: D/libEGL(3789): loaded /system/lib/egl/libGLESv1_CM_tegra.so
02-09 10:12:24.946: D/libEGL(3789): loaded /system/lib/egl/libGLESv2_tegra.so
02-09 10:12:24.966: D/OpenGLRenderer(3789): Enabling debug mode 0

0 个答案:

没有答案