簡體   English   中英

致命異常:主要錯誤 - Android開發

[英]FATAL EXCEPTION: main error - Android development

我目前正在制作一個Android應用程序,我正試圖解決這個問題。 每當我編譯我的代碼並將其編碼到模擬器上時,它最初會加載以下錯誤:

05-22 00:12:54.753: W/dalvikvm(1631): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-22 00:12:54.783: E/AndroidRuntime(1631): FATAL EXCEPTION: main
05-22 00:12:54.783: E/AndroidRuntime(1631): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.ActivityThread.access$1300(ActivityThread.java:123)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.os.Looper.loop(Looper.java:137)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.ActivityThread.main(ActivityThread.java:4424)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at java.lang.reflect.Method.invokeNative(Native Method)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at java.lang.reflect.Method.invoke(Method.java:511)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at dalvik.system.NativeStart.main(Native Method)
05-22 00:12:54.783: E/AndroidRuntime(1631): Caused by: java.lang.NullPointerException
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
05-22 00:12:54.783: E/AndroidRuntime(1631):     at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
05-22 00:12:54.783: E/AndroidRuntime(1631):     ... 11 more

然后它會在關閉力量的情況下將我從應用程序中踢出來,但它會在不久后自動啟動並運行得很好。 如果我關閉應用並殺死它,它不會強制關閉或任何東西。 就在它最初在模擬器上啟動時。 我想知道這是什么原因。 以下是第二次加載后彈出的消息:

05-22 00:13:07.113: D/dalvikvm(1664): GC_FOR_ALLOC freed 38K, 3% free 9110K/9347K, paused 61ms
05-22 00:13:07.165: I/dalvikvm-heap(1664): Grow heap (frag case) to 12.525MB for 3732496-byte allocation
05-22 00:13:07.263: D/dalvikvm(1664): GC_CONCURRENT freed 1K, 2% free 12754K/12999K, paused 5ms+5ms
05-22 00:13:07.543: D/dalvikvm(1664): GC_FOR_ALLOC freed <1K, 2% free 12755K/12999K, paused 37ms
05-22 00:13:07.573: I/dalvikvm-heap(1664): Grow heap (frag case) to 14.502MB for 2073616-byte allocation
05-22 00:13:07.753: D/dalvikvm(1664): GC_CONCURRENT freed <1K, 2% free 14780K/15047K, paused 5ms+5ms
05-22 00:13:08.033: D/gralloc_goldfish(1664): Emulator without GPU emulation detected.

我將為您提供您需要的任何和所有編碼,但不幸的是我不知道這個錯誤會在哪里? 我的程序里面有很多文件,所以如果可能的話我寧願不發布所有文件。

對不起,這個問題沒有提供太多信息,我只是不知道要給你什么信息(如果有意義的話?)請回復並告訴我你需要什么信息,謝謝你的任何和所有幫助

編輯

這是我的splash.java

package com.food;

import com.food.odu.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

//creating a splash effect so the company logo appears for a few seconds before the program
public class Splash extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);  //defined the reference id 'splash' in the splash.xml file

        Thread timer = new Thread(){    //creates a new timer for our splash effect
            public void run(){   //runs the splash program
                try{
                     sleep(5000);    //attempts to run the splash picture for 5000 milliseconds (5 seconds)
                   } catch(InterruptedException e){
                      e.printStackTrace();    //if that doesn't work, this line is debugging information
                      }finally{
                        Intent openStartingPoint = new Intent("com.rhodes.jacob.COM.FOOD.ODUACTIVITY"); //creating an intent which is basically a reference to the Android Manifest
                        startActivity(openStartingPoint);                                               //file saying that when this intent is called, to go to the address at that name in the Android Manifest file
                      }
                  }

        };

        timer.start();

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }



}

這是我的oduActivity.java(我的主要,我想)

package com.food;


import com.food.odu.R;
//import com.food.odu.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;



public class oduActivity extends Activity {
    /** Called when the activity is first created. */

    Button Cafe1201, Legends, Rogers, Faculty;
    TextView display;


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);        
        setContentView(R.layout.main);

        Button Cafe1201 = (Button)findViewById(R.id.cafe1201);
        Button Legends = (Button)findViewById(R.id.legends);
        Button Rogers = (Button)findViewById(R.id.rogers);
        Button Faculty = (Button)findViewById(R.id.fac_n_staff);

  //    Button Legal = (Button)findViewById(R.id.legal);
  //    Button Other = (Button)findViewById(R.id.other);
  //    Button About = (Button)findViewById(R.id.aboutUs);
        //Button Mainpage = (Button)findViewById(R.id.main_page);

        //Changes page to the cafe1201 page
        Cafe1201.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent whichCafe = new Intent(oduActivity.this,cafe1201.class);
                startActivity(whichCafe);

            }
        });


         //changes page to the legends page
          Legends.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Intent whichCafe = new Intent(oduActivity.this,legends.class);
                    startActivity(whichCafe);

                }
            }); 


          //changes page to the rogers page
          Rogers.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  Intent whichCafe = new Intent(oduActivity.this,rogers.class);
                  startActivity(whichCafe);

              }
          }); 


          //changes page to the faculty page
          Faculty.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  Intent whichCafe = new Intent(oduActivity.this,faculty.class);
                  startActivity(whichCafe);

              }
          }); 


    }

    //Options menu
    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        // TODO Auto-generated method stub
        super.onCreateOptionsMenu(menu);
        MenuInflater blowUp = getMenuInflater();
        blowUp.inflate(R.menu.menu, menu);
        return true;

    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch(item.getItemId()){

        case R.id.main_page:

            Intent whichOption = new Intent(oduActivity.this,oduActivity.class);
            startActivity(whichOption);
            break;
        case R.id.other:

            whichOption = new Intent(oduActivity.this,menu.class);
            startActivity(whichOption);
            break;
        case R.id.aboutUs:

            whichOption = new Intent(oduActivity.this,aboutUs.class);
            startActivity(whichOption);
            break;
        case R.id.legal:

            whichOption = new Intent(oduActivity.this,legal.class);
            startActivity(whichOption);
            break;

        }
        return false;
    }






     //   display = (TextView) findViewById(R.id.tvDisplay);
  //  }
 }

我在這里看到空指針。 您應該設置斷點並嘗試使用其他模擬器...

為什么不試試這個,

Intent openStartingPoint = new Intent(Splash.this,ODUACTIVITY.class); //creating an intent which is basically a reference to the Android Manifest
                        startActivity(openStartingPoint);  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM