闪屏崩溃(Logcat 错误)

Posted

技术标签:

【中文标题】闪屏崩溃(Logcat 错误)【英文标题】:Splash screen crashes (Logcat errors) 【发布时间】:2015-12-09 12:53:23 【问题描述】:

我正在开发一个 android 应用程序,当我运行我的应用程序时它崩溃了 每次。我在这里发布了一些 logcat 错误。我不知道该怎么办。 这是我的启动画面代码:

@Override
protected void onCreate(Bundle savedInstanceState) 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Thread welcomeThread = new Thread() 

        @Override
        public void run() 
            try 
                super.run();
                sleep(2000);  //Delay of 3 seconds
             catch (Exception e) 

             finally 

                Intent i = new Intent(MainActivity.this,
                        MaainActivity.class);
                startActivity(i);
                finish();
            
        
    ;
    welcomeThread.start();


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


@Override
public boolean onOptionsItemSelected(MenuItem item) 
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) 
        return true;
    

    return super.onOptionsItemSelected(item);


第二页:

EditText etPhoneNumber;
EditText RandomNumber;
Button Submit;
Button response;
protected String PhoneNumber;
protected String EnteredNumber;



protected void onCreate(Bundle savedInstanceState) 
    super.onCreate(savedInstanceState);

    StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.activity_main);
    etPhoneNumber=(EditText) findViewById(R.id.editText1);
    RandomNumber =(EditText) findViewById(R.id.editText2);

    Submit= (Button) findViewById(R.id.button1);
    response = (Button)findViewById(R.id.button2);  
     response.setOnClickListener(this);
    Submit.setOnClickListener(new View.OnClickListener()
    
        InputStream is=null;
        @Override
        public void onClick(View arg0) 
            // TODO Auto-generated method stub

             PhoneNumber=""+etPhoneNumber.getText().toString();


            Log.i("Tag","Phone number: "+PhoneNumber);

            List<NameValuePair> nameValuePairs =new ArrayList<NameValuePair>(1);

            nameValuePairs.add(new BasicNameValuePair("PhoneNumber", PhoneNumber));
            try
                HttpClient httpClient= new DefaultHttpClient();
                HttpPost httpPost=new HttpPost("http://192.168.0.4/older/index.php");                   
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response =httpClient.execute(httpPost);
                Log.i("Tag","UR;"+ response);
                HttpEntity entity =response.getEntity();
                Log.i("Tag","UR;"+ entity);
                is = entity.getContent();
                String msg="Data is entered successfully" +PhoneNumber;
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
            
            catch(ClientProtocolException e)
            
                Log.e("ClientProtocol","Log_tag");
                e.printStackTrace();
                System.out.println("Excep: "+e);
            
            catch(IOException e)
            
                Log.e("Log_tag","IOException"); 
                e.printStackTrace();
            
        
    );

//New Thread
    Thread thread =new Thread (new Runnable() 
     
        @Override public void run() 

    


     OnClickListener stopListener = new OnClickListener() 
          InputStream is=null;

             public void onClick(View v) 

                 String result = "";
                 EnteredNumber=""+RandomNumber.getText().toString();
                 List<NameValuePair> nameValuePairs =new ArrayList<NameValuePair>(1);
                 nameValuePairs.add(new BasicNameValuePair("PhoneNumber", PhoneNumber));
                 nameValuePairs.add(new BasicNameValuePair("EnteredNumber", EnteredNumber));
                 Toast.makeText(getApplicationContext(), "You entered"+ EnteredNumber, Toast.LENGTH_LONG).show();
                 try
                      
                        HttpClient httpClient= new DefaultHttpClient();
                        HttpPost httpPost=new HttpPost("http://192.168.0.4/older/check.php");
                        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                        HttpResponse response =httpClient.execute(httpPost);
                        HttpEntity entity =response.getEntity();
                        is = entity.getContent();
                        
                   catch(ClientProtocolException e)
                    
                        Log.e("ClientProtocol","Log_tag");
                        e.printStackTrace();
                        System.out.println("Excep: "+e);    
                    
                    catch(IOException e)
                    
                        Log.e("Log_tag","IOException"); 
                        e.printStackTrace();    
                    try
                        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                        StringBuilder sb = new StringBuilder();
                        String line = null;
                        while ((line = reader.readLine()) != null) 
                                sb.append(line + "\n");
                        
                        reader.close();
                        is.close();

                        result=sb.toString();
                catch(Exception e)
                        Log.e("log_tag", "Error converting result "+e.toString());
                

                try
                    Log.i("log_tag","result: "+ result); 

                        JSONObject jArray = new JSONObject(result);
                        String returnString = "";
                        returnString = jArray.getString("RandomNumber");
                        Toast.makeText(getApplicationContext(), "json is :" + returnString, Toast.LENGTH_LONG).show();
                        Log.i("log_tag","value:"+jArray.getString("RandomNumber"));
                        if (!jArray.isNull("returnString")) 
                            JSONObject Object = jArray.getJSONObject("returnString");
                        
                       boolean retVal;
                        retVal = returnString.equals("0");
                        if(retVal) 
                         Toast.makeText(getApplicationContext(), "User verified ", Toast.LENGTH_LONG).show();
                            Intent intent = new Intent(MaainActivity.this, ContactList.class);
                            startActivity(intent);


                        
                        else  Toast.makeText(getApplicationContext(), "not verified", Toast.LENGTH_LONG).show();
                        
                        

                catch(JSONException e)
                        Log.e("log_tag", "Error parsing data "+e.toString());
                

              ; 

      response.setOnClickListener(stopListener); 


    );

      thread.start();   
     




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


@Override
public boolean onOptionsItemSelected(MenuItem item) 
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) 
        return true;
    

    return super.onOptionsItemSelected(item);



@Override
public void onClick(View v) 
    // TODO Auto-generated method stub



Logcat 错误:

09-13 07:02:49.884: E/AndroidRuntime(1395): FATAL EXCEPTION: main
09-13 07:02:49.884: E/AndroidRuntime(1395): Process: com.example.verificationdatabase, PID: 1395
09-13 07:02:49.884: E/AndroidRuntime(1395): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.internal.app.AppCompatViewInflater.themifyContext(AppCompatViewInflater.java:168)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:79)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:912)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:966)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3022)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3085)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1678)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.example.verificationdatabase.MainActivity.onCreate(MainActivity.java:14)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.Activity.performCreate(Activity.java:5231)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.os.Looper.loop(Looper.java:136)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at android.app.ActivityThread.main(ActivityThread.java:5001)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at java.lang.reflect.Method.invokeNative(Native Method)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at java.lang.reflect.Method.invoke(Method.java:515)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-13 07:02:49.884: E/AndroidRuntime(1395):     at dalvik.system.NativeStart.main(Native Method)
09-13 07:19:56.444: I/Process(1395): Sending signal. PID: 1395 SIG: 9

【问题讨论】:

就在最顶部,它告诉您类定义有问题。 现在 logcat 显示这个 09-13 08:17:20.704: E/AndroidRuntime(1818): FATAL EXCEPTION: main 09-13 08:17:20.704: E/AndroidRuntime(1818): Process : com.example.verificationdatabase, PID: 1818 09-13 08:17:20.704: E/AndroidRuntime(1818): java.lang.RuntimeException: 无法启动活动 ComponentInfocom.example.verificationdatabase/com.example.verificationdatabase. MaainActivity:java.lang.NullPointerException 09-13 08:17:20.704:E/AndroidRuntime(1818):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 【参考方案1】:

您能否检查一下您是否在清单文件中添加了此活动。我认为它不见了。

【讨论】:

现在我的控制台显示此错误我之前从未见过该错误:( [2015-09-13 06:06:34 - Dex Loader] 无法执行 dex:多个 dex 文件定义 Landroid/support /v7/app/ActionBar$DisplayOptions; [2015-09-13 06:06:34 - VerificationDatabase] 转换为 Dalvik 格式失败:无法执行 dex:多个 dex 文件定义 Landroid/support/v7/app/ActionBar$DisplayOptions; [2015-09-13 06:41:40 - Dex Loader] 无法执行 dex:多个 dex 文件定义 Landroid/support/v7/app/ActionBar$DisplayOptions;; 现在我的 logcat 中有一个空指针异常。 09-15 02:59:27.040: E/AndroidRuntime(1004): 致命异常: main09-15 02:59:27.040: E/AndroidRuntime(1004): Process:com.example.verificationdatabase, PID: 1004 09-15 02 :59:27.040:E / AndroidRuntime(1004):java.lang.RuntimeException:无法启动活动ComponentInfo com.example.verificationdatabase/com.example.verificationdatabase.MaainActivity:java.lang.NullPointerException 09-15 02:59 :27.040: E/AndroidRuntime(1004): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)09-15 02:59:27.040: E/AndroidRuntime(1004) 你能把你的活动粘贴到清单文件中吗?在这里,我想我表现出一些拼写错误。

以上是关于闪屏崩溃(Logcat 错误)的主要内容,如果未能解决你的问题,请参考以下文章

带有半透明闪屏的 Android 崩溃

我的应用程序在 ios14 上崩溃 应用程序在闪屏上崩溃?

当我打开 iPhone 3G 时,应用程序第二次在闪屏上崩溃

为啥手机会闪屏,总是闪屏怎么办?

Phonegap 构建错误“不支持插件:闪屏”

通用应用程序闪屏错误