我目前正在制作一个 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);
  //  }
 }