帮助我,我在logcat中遇到了这样的错误:
12-10 17:47:55.911 15459-15459/com.fikri.fadillah.joblist E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fikri.fadillah.joblist, PID: 15459
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fikri.fadillah.joblist/com.fikri.fadillah.joblist.LoginActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5354)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class Button
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.fikri.fadillah.joblist.LoginActivity.onCreate(LoginActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6021)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5354)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/button.xml from drawable resource ID #0x7f060054
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2469)
at android.content.res.Resources.loadDrawable(Resources.java:2371)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3738)
at android.widget.TextView.<init>(TextView.java:679)
at android.widget.Button.<init>(Button.java:111)
at android.widget.Button.<init>(Button.java:107)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:71)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:67)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.fikri.fadillah.joblist.LoginActivity.onCreate(LoginActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6021)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5354)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/item_background_material.xml from color state list resource ID #0x108045f
at android.content.res.Resources.loadColorStateList(Resources.java:2582)
at android.content.res.TypedArray.getColor(TypedArray.java:395)
at android.graphics.drawable.GradientDrawable.updateGradientDrawableGradient(GradientDrawable.java:1287)
at android.graphics.drawable.GradientDrawable.inflateChildElements(GradientDrawable.java:1136)
at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:990)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1017)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2459)
at android.content.res.Resources.loadDrawable(Resources.java:2371)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3738)
at android.widget.TextView.<init>(TextView.java:679)
at android.widget.Button.<init>(Button.java:111)
at android.widget.Button.<init>(Button.java:107)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:71)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:67)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.fikri.fadillah.joblist.LoginActivity.onCreate(LoginActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6021)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5354)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag ripple
at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:148)
at android.content.res.ColorStateList.createFro
这是我的LoginActivity.class
private EditText usernameText, passwordText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
TextView redirectRegister = findViewById(R.id.redirectRegister);
redirectRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
usernameText = findViewById(R.id.usernameLogin);
passwordText = findViewById(R.id.passwordLogin);
Button btnLogin = findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
userLogin();
}
});
}
private void userLogin() {
final String username = usernameText.getText().toString();
final String password = passwordText.getText().toString();
if (TextUtils.isEmpty(username)) {
usernameText.setError("Please enter your username");
usernameText.requestFocus();
return;
}
if (TextUtils.isEmpty(password)) {
passwordText.setError("Please enter your password");
passwordText.requestFocus();
return;
}
@SuppressLint("StaticFieldLeak")
class UserLogin extends AsyncTask<Void, Void, String> {
private ProgressBar progressBar;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressBar.setVisibility(View.GONE);
try {
JSONObject obj = new JSONObject(s);
if (!obj.getBoolean("error")) {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
JSONObject userJson = obj.getJSONObject("user");
User user = new User(userJson.getInt("id"), userJson.getString("nama"), userJson.getString("username"));
SharedPrefManager.getInstance(getApplicationContext()).userLogin(user);
finish();
startActivity(new Intent(getApplicationContext(), MainActivity.class));
} else {
Toast.makeText(getApplicationContext(), "Invalid username or password", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... voids) {
RequestHandler requestHandler = new RequestHandler();
HashMap<String, String> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
return requestHandler.sendPostRequest(Api.URL_LOGIN, params);
}
}
UserLogin ul = new UserLogin();
ul.execute();
}
答案 0 :(得分:0)
形成您的异常,它告诉我找不到两个资源检查这些xml文件中可用的所有资源或您引用它们的位置,还要检查所有可绘制文件夹及其兄弟文件是否包含您引用的文件,即一个文件存在于drawable中,也应该存在于drawable-v21中。