Android应用程序似乎在KitKat 4.4上启动时崩溃了。

时间:2018-09-05 13:17:15

标签: java android xml android-4.4-kitkat inflate-exception

我的应用程序安装在相对较新的运行Oreo 8.0的华为上时,能够顺利启动和运行该应用程序。该应用程序还可以在运行Lollipop的Nexus模拟器上正常运行。但是,在运行KitKat 4.4的另一部手机上,该应用在启动时崩溃。

我认为在添加默认的NavigationDrawerActivity时出现了问题。

  

09-05 14:05:57.285 30968-30968 /? E / AndroidRuntime:致命异常:   主要       流程:com.example.a_phi.myapplication,PID:30968       java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.a_phi.myapplication / com.example.a_phi.myapplication.LoginActivity}:   android.view.InflateException:二进制XML文件第2行:错误   充气课           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)           在android.app.ActivityThread.access $ 1100(ActivityThread.java:141)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1238)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:136)           在android.app.ActivityThread.main(ActivityThread.java:5333)           在java.lang.reflect.Method.invokeNative(本机方法)           在java.lang.reflect.Method.invoke(Method.java:515)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)           在dalvik.system.NativeStart.main(本机方法)        原因:android.view.InflateException:二进制XML文件第2行:膨胀类错误           在android.view.LayoutInflater.createView(LayoutInflater.java:620)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)           在android.view.LayoutInflater.inflate(LayoutInflater.java:469)           在android.view.LayoutInflater.inflate(LayoutInflater.java:397)           在android.view.LayoutInflater.inflate(LayoutInflater.java:353)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)           在android.app.Activity.setContentView(Activity.java:1958)           在com.example.a_phi.myapplication.LoginActivity.onCreate(LoginActivity.java:44)           在android.app.Activity.performCreate(Activity.java:5340)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)           在android.app.ActivityThread.access $ 1100(ActivityThread.java:141)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1238)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:136)           在android.app.ActivityThread.main(ActivityThread.java:5333)           在java.lang.reflect.Method.invokeNative(本机方法)           在java.lang.reflect.Method.invoke(Method.java:515)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)           在dalvik.system.NativeStart.main(本机方法)        造成原因:java.lang.reflect.InvocationTargetException           在java.lang.reflect.Constructor.constructNative(本机方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:423)           在android.view.LayoutInflater.createView(LayoutInflater.java:594)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)           在android.view.LayoutInflater.inflate(LayoutInflater.java:469)           在android.view.LayoutInflater.inflate(LayoutInflater.java:397)           在android.view.LayoutInflater.inflate(LayoutInflater.java:353)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)           在android.app.Activity.setContentView(Activity.java:1958)           在com.example.a_phi.myapplication.LoginActivity.onCreate(LoginActivity.java:44)           在android.app.Activity.performCreate(Activity.java:5340)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)           在android.app.ActivityThread.access $ 1100(ActivityThread.java:141)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1238)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:136)           在android.app.ActivityThread.main(ActivityThread.java:5333)           在java.lang.reflect.Method.invokeNative(本机方法)           在java.lang.reflect.Method.invoke(Method.java:515)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)           在dalvik.system.NativeStart.main(本机方法)        造成原因:java.lang.NullPointerException           在com.huawei.android.content.res.ResourcesEx.getThemeDrawable(ResourcesEx.java:655)           在com.huawei.android.content.res.ResourcesEx.loadDrawable(ResourcesEx.java:623)           在android.content.res.TypedArray.getDrawable(TypedArray.java:616)           在android.view.View。(View.java:3573)           在android.view.ViewGroup。(ViewGroup.java:470)           在android.widget.LinearLayout。(LinearLayout.java:179)           在android.widget.LinearLayout。(LinearLayout.java:175)           在java.lang.reflect.Constructor.constructNative(本机方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:423)           在android.view.LayoutInflater.createView(LayoutInflater.java:594)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)           在android.view.LayoutInflater.inflate(LayoutInflater.java:469)           在android.view.LayoutInflater.inflate(LayoutInflater.java:397)           在android.view.LayoutInflater.inflate(LayoutInflater.java:353)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)           在android.app.Activity.setContentView(Activity.java:1958)           在com.example.a_phi.myapplication.LoginActivity.onCreate(LoginActivity.java:44)           在android.app.Activity.performCreate(Activity.java:5340)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)           在android.app.ActivityThread.access $ 1100(ActivityThread.java:141)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1238)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:136)           在android.app.ActivityThread.main(ActivityThread.java:5333)           在java.lang.reflect.Method.invokeNative(本机方法)           在java.lang.reflect.Method.invoke(Method.java:515)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:895)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)           在dalvik.system.NativeStart.main(本机方法)

LoginActvity

public class LoginActivity extends Activity {


    private UserLoginTask mAuthTask = null;

    // UI references.
    private EditText mEmailView;
    private EditText mPasswordView;
    private TextView mRegistrationScreen;
    private View mProgressView;
    private View mLoginFormView;
    public String id;

    @Override
    @TargetApi(19)
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);

        setContentView(R.layout.activity_login_registration);
        // Set up the login form.
        mEmailView = (EditText) findViewById(R.id.email);
        mPasswordView = (EditText) findViewById(R.id.password);

        Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);

        mLoginFormView = findViewById(R.id.login_form);
        mProgressView = findViewById(R.id.login_progress);
        mRegistrationScreen = findViewById(R.id.registerLink);
        mEmailSignInButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                String emailAddress = mEmailView.getText().toString().trim();
                String password = mPasswordView.getText().toString().trim();
                UserLoginTask callDOIB = new UserLoginTask();
                try {
                    String loginSuccessFail = callDOIB.execute(emailAddress, password).get();
                    try {
                        JSONObject jsonObject = new JSONObject(loginSuccessFail);
                        id = jsonObject.getString("id");
                        //JSONObject id = jArray.getJSONObject(0);
                        System.out.println("json object at LoginActivity id is "+id);
                        authoriseLogin(loginSuccessFail, id);
                    }catch (JSONException e){
                        e.printStackTrace();
                    }

                }catch(InterruptedException e){
                    e.printStackTrace();
                }
                catch (ExecutionException e){
                    e.printStackTrace();
                }
            }
        });

        mRegistrationScreen.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                Intent loadRegistration = new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(loadRegistration);
            }
        });
    }






    public void authoriseLogin(String authorise, String id){
        if (authorise.contains("id")) {
            System.out.println(" accessLRA.authoriseLogin login has been called");
            Session session = new Session(getApplicationContext());
            session.setId(id);
            Intent loadPersonal = new Intent(LoginActivity.this, MainActivity.class);
            startActivity(loadPersonal);

            System.out.println("Login has been authorised");
        }
        else{
            System.out.println("Incorrect username or password");
        }
    }





    }

使用setContentView()加载布局文件时,这给了我一个膨胀的异常

  

java.lang.RuntimeException:无法启动活动   ComponentInfo {com.example.a_phi.myapplication / com.example.a_phi.myapplication.LoginActivity}:   android.view.InflateException:二进制XML文件第2行:错误   膨胀类

1 个答案:

答案 0 :(得分:0)

正如评论部分所建议的,实际上我确实缺少一些其他的-v21文件夹,这些文件夹支持Android KitKat的API级别21。由于某种原因,我没有将它们移到我的新项目中。现在正在运行,谢谢。