“应用程序始终强制关闭”,并且应用程序始终随时停止调试错误

时间:2018-07-26 06:36:13

标签: android android-studio debugging

这是我的程序错误

  

07-26 13:16:11.621 3436-3436 / com.mercy.mercyshop E / Android运行时:致命异常:主要       流程:com.mercy.mercyshop,PID:3436       java.lang.RuntimeException:无法启动活动ComponentInfo {com.mercy.mercyshop / com.mercy.mercyshop.WelcomeActivity}:android.view.InflateException:二进制XML文件行#0:尝试调用虚拟方法'boolean java.lang .String.equals(java.lang.Object)'在空对象引用上           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)           在android.app.ActivityThread.-wrap11(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:148)           在android.app.ActivityThread.main(ActivityThread.java:5417)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)        原因:android.view.InflateException:二进制XML文件第0行:尝试在空对象引用上调用虚拟方法'boolean java.lang.String.equals(java.lang.Object)'           在android.view.LayoutInflater.inflate(LayoutInflater.java:539)           在android.view.LayoutInflater.inflate(LayoutInflater.java:423)           在android.view.LayoutInflater.inflate(LayoutInflater.java:374)           在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)           在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)           在com.mercy.mercyshop.WelcomeActivity.onCreate(WelcomeActivity.java:41)           在android.app.Activity.performCreate(Activity.java:6237)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)           在android.app.ActivityThread.-wrap11(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:148)           在android.app.ActivityThread.main(ActivityThread.java:5417)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)        原因:java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'boolean java.lang.String.equals(java.lang.Object)'           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:835)           在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)           在android.view.LayoutInflater.inflate(LayoutInflater.java:515)           在android.view.LayoutInflater.inflate(LayoutInflater.java:423)           在android.view.LayoutInflater.inflate(LayoutInflater.java:374)           在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)           在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)           在com.mercy.mercyshop.WelcomeActivity.onCreate(WelcomeActivity.java:41)           在android.app.Activity.performCreate(Activity.java:6237)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)           在android.app.ActivityThread.-wrap11(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:148)           在android.app.ActivityThread.main(ActivityThread.java:5417)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)           com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

如果我总是像这样进行调试,并且如果我不进行调试就一直使用SLAVE_AAPT_TIMEOUT = 5秒钟以上,那么我可以尝试一下,但是无法解决问题,你们可以帮我吗?非常感谢我

欢迎活动

public class WelcomeActivity extends AppCompatActivity {

private ViewPager viewPager;
private LinearLayout layoutDot;
private TextView[]dotstv;
private int[]layouts;
private Button btnSkip;
private Button btnNext;
private MyPagerAdapter pagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(!isFirstTimeStartApp()){
        startMainActivity();
        finish();
    }

    setStatusBarTransparent();

    setContentView(R.layout.activity_welcome);

    viewPager= findViewById(R.id.view_pager);
    layoutDot = findViewById(R.id.dotLayout);
    btnNext = findViewById(R.id.btn_next);
    btnSkip = findViewById(R.id.btn_skip);
    //Ketika User Memencet Skip, Mulai Main Activity
    btnSkip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startMainActivity();
        }
    });

    btnNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int currentPage = viewPager.getCurrentItem()+1;
            if(currentPage< layouts.length){
                //move to next page
                viewPager.setCurrentItem(currentPage);
            }else {
                startMainActivity();
            }
        }
    });

    layouts = new int[]{
            R.layout.slider_1,
            R.layout.slider_2,
            R.layout.slider_3,
            R.layout.slider_4};
    pagerAdapter = new MyPagerAdapter(layouts,getApplicationContext());
    viewPager.setAdapter(pagerAdapter);

    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == layouts.length-1){
                btnNext.setText("START");
                btnSkip.setVisibility(View.GONE);
            }else {
                btnNext.setText("Next");
                btnSkip.setVisibility(View.VISIBLE);
            }
            setDotStatus(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    setDotStatus(0);
}

private boolean isFirstTimeStartApp(){
    SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSliderApp", Context.MODE_PRIVATE);
    return ref.getBoolean("FirstTimeStartFlag", true);
}

private void setFirstTimeStartStatus(boolean stt){
    SharedPreferences ref = getApplicationContext().getSharedPreferences("IntroSliderApp", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = ref.edit();
    editor.putBoolean("FirstTimeStartFlag", stt);
    editor.commit();
}

private  void setDotStatus(int page){
    layoutDot.removeAllViews();
    dotstv = new TextView[layouts.length];
    for (int i = 0; i<dotstv.length; i++){
        dotstv[i] = new TextView(this);
        dotstv[i].setText(Html.fromHtml("&#8226"));
        dotstv[i].setTextSize(30);
        dotstv[i].setTextColor(Color.parseColor("#a9b4bb"));
        layoutDot.addView(dotstv[i]);
    }
    //Mengeset Dots Layout yang ada

    if (dotstv.length>0){
        dotstv[page].setTextColor(Color.parseColor("#ffffff"));
    }
}

private void startMainActivity(){
    setFirstTimeStartStatus(false);
    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
    finish();
}
private void setStatusBarTransparent(){
    if (Build.VERSION.SDK_INT >=23){
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }
   }

  }

1 个答案:

答案 0 :(得分:0)

如果不提供适当的代码,就不可能确切知道。

但是,当活动开始时,充气机似乎正在发生故障。这部分:

boolean java.lang.String.equals(java.lang.Object)' on a null object reference

建议您有一个未正确实例化/定义的对象。没有更多的信息,就很难知道。