Error inflating class MaterialEditText - java

I am new to android development. Please help me in identifying the issue in my code. My code is getting into InflateException.
Please help me.
My code is existing with error related to MaterialEditText class and I have searched for the solution but till now didn't get the working solution.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_vertical"
tools:context="com.android.appgallery.quizworld.MainActivity">
<ImageView
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:src="#drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/wrap_login"
/>
<RelativeLayout
android:id="#+id/wrap_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="8dp"
>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/info_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:com.rengwuxian.materialedittext="http://schemas.android.com/tools"
android:layout_margin="8dp"
app:cardElevation="4dp">
<LinearLayout
android:padding="16dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtUser"
android:hint="User Name"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext:MaterialEditText
android:id="#+id/edtPassword"
android:hint="Password"
android:textColorHint="#color/colorPrimary"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:met_baseColor="#color/colorPrimary"
app:met_floatingLabel="highlight"
app:met_primaryColor="#color/colorPrimary"
app:met_singleLineEllipsis="true"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_below="#id/info_login"
android:orientation="horizontal"
android:weightSum="2"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_sign_up"
android:text="Sign Up"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_sign_in"
android:text="Sign In"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#1CB3BC</item>
</style>
</resources>
MainActivity
package com.android.appgallery.quizworld;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.appgallery.quizworld.BroadcastReceiver.AlarmReceiver;
import com.android.appgallery.quizworld.Common.Common;
import com.android.appgallery.quizworld.Model.User;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
MaterialEditText edtNewUser,edtNewPassword,edtNewEmail; //For Sign Up
MaterialEditText edtUser,edtPassword; //For Login
Button btnSignUp,btnSignIn;
FirebaseDatabase database;
DatabaseReference users;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
try {
setContentView(R.layout.activity_main);
}catch(Exception e){
//InflateException ex=new InflateException(parser.getPositionDescription()+" "+e.getMessage());
InflateException ex=new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
}
registerAlarm();
database= FirebaseDatabase.getInstance();
users=database.getReference("Users");
edtUser=(MaterialEditText) findViewById(R.id.edtUser);
edtPassword=(MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn= (Button) findViewById(R.id.btn_sign_in);
btnSignUp= (Button) findViewById(R.id.btn_sign_up);
btnSignUp.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
showSignUpDialog();
}
});
btnSignIn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
signIn(edtUser.getText().toString(),edtPassword.getText().toString());
}
});
}
private void registerAlarm() {
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,9);
calendar.set(Calendar.MINUTE,40);
calendar.set(Calendar.SECOND,0);
Intent intent=new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)this.getSystemService(this.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}
private void signIn(final String user, final String pwd){
users.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.child(user).exists()){
if(!user.isEmpty()){
User login=dataSnapshot.child(user).getValue(User.class);
if(login.getPassword().equals(pwd)){
Intent homeActivity=new Intent(MainActivity.this,Home.class);
Common.currentUser= login;
startActivity(homeActivity);
finish();
}else{
Toast.makeText(MainActivity.this,"Wrong Password",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"Please enter your user name.",Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this,"User does not exist",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void showSignUpDialog(){
AlertDialog.Builder alertDialog= new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Sign Up");
alertDialog.setMessage("Please fill full information");
LayoutInflater inflater=this.getLayoutInflater();
View sign_up_layout = inflater.inflate(R.layout.sign_up_layout,null);
edtNewUser=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewUserName);
edtNewPassword=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewPassword);
edtNewEmail=(MaterialEditText) sign_up_layout.findViewById(R.id.edtNewEmail);
alertDialog.setView(sign_up_layout);
//Check for the icon
alertDialog.setIcon(R.drawable.ic_account_circle_black_24dp);
alertDialog.setNegativeButton("NO",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i){
dialogInterface.dismiss();
}
});
alertDialog.setPositiveButton("YES",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialogInterface, int i) {
final User user = new User(edtNewUser.getText().toString(), edtNewPassword.
getText().toString(), edtNewEmail.getText().toString());
users.addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.child(user.getUserName()).exists())
Toast.makeText(MainActivity.this, "User already exists!!!", Toast.LENGTH_SHORT).show();
else {
users.child(user.getUserName()).setValue(user);
Toast.makeText(MainActivity.this, "User registration successful!!!", Toast.LENGTH_SHORT).show();
}
}
public void onCancelled(DatabaseError databaseError) {
}
});
dialogInterface.dismiss();
}
});
alertDialog.show();
}
}
Error Snippet:
01-18 23:14:13.656 23773-23773/? I/art: Late-enabling -Xcheck:jni
01-18 23:14:13.726 23773-23773/com.android.appgallery.quizworld D/LenovoAppIconTheme: ExtraResources;cleanCachedIcon;clear cache..
01-18 23:14:14.049 23773-23773/com.android.appgallery.quizworld W/System: ClassLoader referenced unknown path:
/data/app/com.android.appgallery.quizworld-2/lib/arm
01-18 23:14:14.079 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping
initialization.
01-18 23:14:14.095 23773-23773/com.android.appgallery.quizworld W/InstanceID/Rpc: Found 10014
01-18 23:14:14.102 23773-23773/com.android.appgallery.quizworld D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping
initialization.
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: App measurement is starting up, version: 10298
01-18 23:14:14.144 23773-23773/com.android.appgallery.quizworld I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: Collection enabled
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld V/FA: App package, google app id: com.android.appgallery.quizworld,
1:778477946548:android:1b7a8c110537f112
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app
com.android.appgallery.quizworld
01-18 23:14:14.163 23773-23773/com.android.appgallery.quizworld D/FA: Debug-level message logging enabled
01-18 23:14:14.210 23773-23773/com.android.appgallery.quizworld V/FA: Registered activity lifecycle callback
01-18 23:14:14.212 23773-23773/com.android.appgallery.quizworld I/FirebaseInitProvider: FirebaseApp initialization successful
01-18 23:14:14.213 23773-23773/com.android.appgallery.quizworld I/InstantRun: starting instant run server: is main process
01-18 23:14:14.219 23773-23792/com.android.appgallery.quizworld V/FA: Using measurement service
01-18 23:14:14.225 23773-23792/com.android.appgallery.quizworld V/FA: Connecting to remote service
01-18 23:14:14.297 23773-23773/com.android.appgallery.quizworld W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter
android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList,
android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-18 23:14:14.306 23773-23773/com.android.appgallery.quizworld V/FA: onActivityCreated
01-18 23:14:14.472 23773-23773/com.android.appgallery.quizworld D/AndroidRuntime: Shutting down VM
01-18 23:14:14.473 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.appgallery.quizworld, PID: 23773
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.appgallery.quizworld/com.android.appgallery.quizworld.MainActivity}: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755) 
Caused by: android.view.InflateException: Binary XML file line
#0: Binary XML file line #0: Error inflating class MaterialEditText
Caused by: android.view.InflateException: Binary XML file line
#0: Error inflating class MaterialEditText
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.view.MaterialEditText" on path: DexPathList[[zip file "/data/app/com.android.appgallery.quizworld-2/base.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_0_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_1_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_3_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_4_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_6_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-2/split_lib_slice_7_apk.apk", zip file
"/data/app/com.android.appgallery.quizworld-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.android.appgallery.quizworld-
2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.android.appgallery.quizworld-2/lib/arm, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass
(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView
(LayoutInflater.java:609)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:700)
at
com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView
(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.rInflate
(LayoutInflater.java:861)
01-18 23:14:14.474 23773-23773/com.android.appgallery.quizworld E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren
(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate
(LayoutInflater.java:377)
at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView
(AppCompatActivity.java:140)
at com.android.appgallery.quizworld.MainActivity.onCreate
(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate
(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity
(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage
(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:755)

Related

How to correctly use a snackbar in Android

I have created a simple counter application for Android. I have just started using support libraries and just to test it out, I wanted to show a snackbar which says Hello. Here is my code in the MainActivity.java file :
package com.mapsup.counter;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends Activity {
long count=0;
TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
SharedPreferences sp=getApplicationContext().getSharedPreferences("preferences",Context.MODE_PRIVATE);
count=sp.getLong("count",0);
tv=findViewById(R.id.counter);
tv.setText(String.valueOf(count));
//Create and display a snackbar
Snackbar snackbar = Snackbar.make(tv,"Hello",Snackbar.LENGTH_LONG);
snackbar.show();
}
public void increase(View view) {
++count;
tv.setText(String.valueOf(count));
}
public void decrease(View view) {
if(count>0) {
--count;
tv.setText(String.valueOf(count));
}
}
public void reset(View view) {
count=0;
tv.setText("0");
}
#Override
public void onStop() {
super.onStop();
Context ctx=getApplicationContext();
SharedPreferences sp=ctx.getSharedPreferences("preferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putLong("count",count);
editor.apply();
}
}
Here is the layout main_layout.xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0031A0"
android:orientation="vertical"
android:padding="20dp"
android:id="#+id/root">
<TextView
android:id="#+id/counter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
android:background="#B2FFFFFF"
android:gravity="center"
android:textSize="36sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="increase"
android:text="#string/add"
android:textSize="30sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="decrease"
android:text="#string/subt"
android:textSize="30sp" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="reset"
android:text="#string/reset"
android:textAllCaps="false"
android:textSize="30sp" />
</LinearLayout>
When I am running the app, the app crashes. The logcat shows this as the error message :
2020-02-03 00:20:10.015 12849-12849/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mapsup.counter, PID: 12849
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mapsup.counter/com.mapsup.counter.MainActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:164)
at com.mapsup.counter.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:6712)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:531)
at android.widget.TextView.<init>(TextView.java:805)
at android.widget.TextView.<init>(TextView.java:727)
at android.widget.TextView.<init>(TextView.java:723)
at java.lang.reflect.Constructor.newInstance0(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:430) 
at android.view.LayoutInflater.createView(LayoutInflater.java:645) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:164) 
at com.mapsup.counter.MainActivity.onCreate(MainActivity.java:23) 
at android.app.Activity.performCreate(Activity.java:6712) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6251) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 
The app runs all fine if I remove the snackbar code.
According to my thinking, creating a snackbar is the same as creating a toast, we just need to replace Toast with Snackbar. Is this correct?
What is my mistake and how to properly use a snackbar?
Please replace tv to rootLayout in Snackbar.make(llRootLayout,"Hello",Snackbar.LENGTH_LONG); as below.
public class MainActivity extends Activity {
long count=0;
TextView tv;|
LinearLayout llRootLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
SharedPreferences sp=getApplicationContext().getSharedPreferences("preferences",Context.MODE_PRIVATE);
count=sp.getLong("count",0);
tv=findViewById(R.id.counter);
llRootLayout=findViewById(R.id.root);
tv.setText(String.valueOf(count));
//Create and display a snackbar
Snackbar snackbar=Snackbar.make(llRootLayout,"Hello",Snackbar.LENGTH_LONG);
snackbar.show();
}
public void increase(View view) {
++count;
tv.setText(String.valueOf(count));
}
public void decrease(View view) {
if(count>0) {
--count;
tv.setText(String.valueOf(count));
}
}
public void reset(View view) {
count=0;
tv.setText("0");
}
#Override
public void onStop() {
super.onStop();
Context ctx=getApplicationContext();
SharedPreferences sp=ctx.getSharedPreferences("preferences",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sp.edit();
editor.putLong("count",count);
editor.apply();
}
}

Google signin in android app

I'm a newbie in programming, trying to implement a Google Signin in my test app.
Folowing Google API documentation I've added all required dependencies at gradle files and registered my test app through OAuth...
Further I wrote a code as described in example provided by Google, but my app crashes at the begining, before any user's action in Virtual device, and does not even set up via APK file at the real device....
What am i doing wrong?
Main (single) activity code:
package ru.podgorny.carcall;
import android.accounts.Account;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;
public class MainActivity extends AppCompatActivity {
SignInButton signInButton;
public static final int RC_SIGN_IN = 07;
public static final String TAG = "MainActivity";
TextView tw1;
TextView tw2;
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
GoogleSignInClient mGSC = GoogleSignIn.getClient(this, gso);
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViews();
}
private void findViews() {
signInButton = findViewById(R.id.idButtonGoogle);
tw1 = findViewById(R.id.textView1);
tw1 = findViewById(R.id.textView2);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.idButtonGoogle:
signIn();
break;
}
}
private void signIn() {
Intent signInIntent = mGSC.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
updateUI(account);
} catch (ApiException e) {
Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
updateUI(null);
}
}
private void updateUI(GoogleSignInAccount account) {
tw1.setText("OK");
tw2.setText("Name: " + account.getGivenName() + ", Family name: " + account.getFamilyName() + ", Email: " + account.getEmail() + " image: " +
account.getPhotoUrl());
}
}
Activity.xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.podgorny.carcall.MainActivity"
>
<com.google.android.gms.common.SignInButton
android:id="#+id/idButtonGoogle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundGravity="top"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idButtonGoogle" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView1" />
</android.support.constraint.ConstraintLayout>
Manifest.xml by default:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.podgorny.carcall">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Console logs :
03-23 08:35:32.774 5682-5682/? E/libprocessgroup: failed to make and chown /acct/uid_10060: Read-only file system
03-23 08:35:32.774 5682-5682/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
03-23 08:35:32.775 5682-5682/? I/art: Not late-enabling -Xcheck:jni (already on)
03-23 08:35:33.180 5682-5682/ru.podgorny.carcall I/InstantRun: starting instant run server: is main process
03-23 08:35:33.746 5682-5682/ru.podgorny.carcall D/AndroidRuntime: Shutting down VM
03-23 08:35:33.753 5682-5682/ru.podgorny.carcall E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.podgorny.carcall, PID: 5682
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{ru.podgorny.carcall/ru.podgorny.carcall.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.content.Context.getMainLooper()' on a null object reference
at android.content.ContextWrapper.getMainLooper(ContextWrapper.java:101)
at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignInClient.<init>(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getClient(Unknown Source)
at ru.podgorny.carcall.MainActivity.<init>(MainActivity.java:35)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1606)
at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
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:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
03-23 08:35:33.827 5682-5695/ru.podgorny.carcall I/art: Background sticky concurrent mark sweep GC freed 2567(255KB) AllocSpace objects, 0(0B) LOS objects, 30% free, 773KB/1117KB, paused 18.376ms total 73.744ms
Try this
GoogleSignInOptions gso ;
GoogleSignInClient mGSC ;
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
mGSC = GoogleSignIn.getClient(this, gso);
findViews();
}

Android Studio Web Browser Project Code Errors

I just developed my first android web browser project,
but it didn't go well.
I found there's some crash on my MainActivity,
But I can't find it.
This is my java code, from my MainActivity.
package org.thunderdot.station;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText editText_search = (EditText) findViewById(R.id.EditText_Uri);
WebView webView = (WebView) findViewById(R.id.webview);
ImageButton button_search = (ImageButton) findViewById(R.id.ImageButton_Search);
ImageButton button_more = (ImageButton) findViewById(R.id.ImageButton_More);
WebSettings webSettings = webView.getSettings();
String default_url = "https://www.google.com";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView.setWebViewClient(new WebViewClient());
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadsImagesAutomatically(true);
webView.loadUrl(default_url);
}
public void onClick_button_search() {
String url = editText_search.getText().toString();
if(url.isEmpty()) {
Toast.makeText(getApplicationContext(), "Please Input URL First!", Toast.LENGTH_SHORT).show();
}
else {
webView.loadUrl(url);
}
}
And Here's my activity_main.xml source.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="org.thunderdot.station.MainActivity"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="368dp"
android:layout_height="60dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
android:gravity="center"
android:id="#+id/LinerLayout_Search" >
<EditText
android:id="#+id/EditText_Uri"
android:layout_width="210dp"
android:layout_height="50dp"
android:hint="Input Url or Text"
android:inputType="textUri"
android:onClick="onClick_button_search"/>
<Space
android:layout_width="5dp"
android:layout_height="0dp" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#mipmap/ic_launcher"
android:id="#+id/ImageButton_Search"/>
<Space
android:layout_width="5dp"
android:layout_height="0dp" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#mipmap/ic_launcher"
android:id="#+id/ImageButton_More"/>
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/LinerLayout_Search"
android:id="#+id/webview"> </WebView>
</RelativeLayout>
And here's my logcat, too.
05-31 12:20:14.241 2709-2709/org.thunderdot.station I/art: Not late-enabling -Xcheck:jni (already on)
05-31 12:20:14.241 2709-2709/org.thunderdot.station W/art: Unexpected CPU variant for X86 using defaults: x86
05-31 12:20:14.431 2709-2709/org.thunderdot.station W/System: ClassLoader referenced unknown path: /data/app/org.thunderdot.station-1/lib/x86
05-31 12:20:14.441 2709-2709/org.thunderdot.station I/InstantRun: starting instant run server: is main process
05-31 12:20:14.542 2709-2709/org.thunderdot.station W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-31 12:20:14.661 2709-2729/org.thunderdot.station I/OpenGLRenderer: Initialized EGL, version 1.4
05-31 12:20:14.661 2709-2729/org.thunderdot.station D/OpenGLRenderer: Swap behavior 1
05-31 12:20:14.661 2709-2729/org.thunderdot.station W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-31 12:20:14.661 2709-2729/org.thunderdot.station D/OpenGLRenderer: Swap behavior 0
05-31 12:21:41.277 2709-2709/org.thunderdot.station D/AndroidRuntime: Shutting down VM
--------- beginning of crash
05-31 12:21:41.278 2709-2709/org.thunderdot.station E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.thunderdot.station, PID: 2709
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.thunderdot.station/org.thunderdot.station.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:33)
at android.support.v7.app.AppCompatDelegateImplN.<init>(AppCompatDelegateImplN.java:33)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:201)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
at org.thunderdot.station.MainActivity.<init>(MainActivity.java:14)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
And here's the java source that calls MainActivity.
package org.thunderdot.station;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TitleScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_title_screen);
Button button = (Button)findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), MainActivity.class);
startActivity(intent);
}
});
}
}

android.view.InflateException: Binary XML file line #16: Error inflating class <unknown> (ListView Maybe?) [duplicate]

This question already exists:
android.view.InflateException: Binary XML file line #16: Error inflating class fragment
Closed 6 years ago.
I made an app, it works well in virtual device and real device, but today my app is throwing exceptions, maybe it is the same with some old errors in here, but I can not find my own answer for this. So, please tell me how to solve it, thanks so much
here is my logcat
FATAL EXCEPTION: main
Process: com.gvc.tvschedule, PID: 1918
android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:121)
at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:2255)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
at android.widget.ListView.onMeasure(ListView.java:1175)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChild(RelativeLayout.java:689)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:473)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
... 48 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b0068}
at android.content.res.Resources.loadDrawable(Resources.java:2073)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:806)
at android.widget.TextView.<init>(TextView.java:618)
... 51
here under is Layout XML: getprogram_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relativeLayoutProgram"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayoutProgram"
android:orientation="vertical"
android:layout_marginTop="40dp">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
</ListView>
<!-- #android:id/list or #id/android:list -->
</RelativeLayout>
</RelativeLayout>
and: view_program_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/programtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="15sp"
android:paddingLeft="6sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/programtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"
android:drawableLeft="#+id/programtime" />
<!-- android:background="#color/blue2" -->
</LinearLayout>
and Java : ProgramPickerActivity.java
package com.gvc.tvschedule;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.gvc.service.DBController;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class ProgramPickerActivity extends Activity {
// DB Class to perform DB related operations
DBController controller = new DBController(this);
// Progress Dialog Object
ProgressDialog prgDialog;
HashMap<String, String> queryValues;
private static String titleTextFromView;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.getprogram_main);
ArrayList<HashMap<String, String>> programList = controller.generalProgram(MainActivity.getNameOfChannel(), DatePickerActivity.getDate());
if (programList.size() != 0) {
// Set the User Array list in ListView
ListAdapter adapter = new SimpleAdapter(getApplicationContext(), programList, R.layout.view_program_entry, new String[] {
"ptime", "ptitle" }, new int[] { R.id.programtime, R.id.programtitle });
ListView myList = (ListView) findViewById(android.R.id.list);
myList.setAdapter(adapter);
myList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
TextView titleVIew = (TextView) view.findViewById(R.id.programtitle);
titleTextFromView = titleVIew.getText().toString();
createPopupWindownForDescription(titleTextFromView);
}
});
}
prgDialog = new ProgressDialog(this);
prgDialog.setMessage("loading...");
prgDialog.setCancelable(false);
}
private void createPopupWindownForDescription(String pTitle){
String content = controller.getDescription(pTitle);
AlertDialog.Builder builder = new AlertDialog.Builder(ProgramPickerActivity.this);
builder.setTitle("Content");
builder.setMessage(content);
builder.show();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
if(prgDialog!=null)
prgDialog.dismiss();
}
public static String getTitleTextFromView(){
return titleTextFromView;
}
}
I think the trouble is related with the listview, because, when no data put on listview, it is fine, but with data, it threw the errors.
I believe your current problem is
<TextView
android:id="#+id/programtitle"
...
android:drawableLeft="#+id/programtime" /> // HERE
You are referencing the other TextView but you should be referencing a Drawable. My guess is that you want to put it to the left of the other TextView?
If this is the case, the LinearLayout will lay them out from left to right by default so you just need to put them in the order that you want them to appear. Also, not a problem but since they are left to right by default, there's no need for
android:orientation="horizontal"
It's not showing when you don't have any items in your ListView because the layout is never inflated so the error is never caught.
Docs
android:id="#+id/list"
use that, you're welcome
PS: Change
ListView myList = (ListView) findViewById(android.R.id.list);
for:
ListView myList = (ListView) findViewById(R.id.list);

Issue with Activities and ListView on Android

I'm new in the world of Android and I have a problem with the use of activities, my problem that I want to make an app using ListView to show a list of categories of business and every business category will has another list with the names of the companies.
My array.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="categorias">
<item >Agencias de Autos y Motos</item>
<item >Agroinsumos</item>
<item >Audio Car</item>
<item >Arquitectura y Construcción</item>
<item >Autolavados</item>
<item >Autopartes</item>
<item >Balnearios</item>
</string-array>
</resources>
This is my MainActivity and its layout:
package com.genebi.rubik;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.app.ListActivity;
import android.content.Intent;
public class MainActivity extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] lista_categorias = getResources().getStringArray(R.array.categorias);
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.lista_categorias, R.id.nombreCategoria, lista_categorias));
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long id) {
String categoria = ((TextView) v).getText().toString();
Intent i = new Intent(getApplicationContext(), ListaPorCategoria.class);
i.putExtra("categoria", categoria);
startActivity(i);
}
});
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/nombreCategoria"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dip"
android:textSize="14sp"
android:textStyle="normal"
/>
</RelativeLayout>
And my problem starts here with the second Activity when i give click on a item of the list showed in MainActivity.class
package com.genebi.rubik;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
public class ListaPorCategoria extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_por_categoria);
TextView txtCategoria = (TextView) findViewById(R.id.etiquetaCategoria);
Intent i = getIntent();
String categoriaSeleccionada = i.getStringExtra("categoria");
txtCategoria.setText(categoriaSeleccionada);
}
}
Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ListaPorCategoria" >
<TextView android:id="#+id/etiquetaCategoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"
android:padding="10dip"
android:textColor="#ffffff"/>
</RelativeLayout>
The application just stop working and I can't see the info of the category that i clicked, apparently it has not errors but i have no idea why is not working, i hope you can help me, thank you.
EDIT
Logcat
06-05 13:45:14.667: D/OpenGLRenderer(20800): Enabling debug mode 0
06-05 13:45:19.692: D/AbsListView(20800): Get MotionRecognitionManager
06-05 13:45:19.732: I/Adreno200-EGLSUB(20800): <ConfigWindowMatch:2087>: Format RGBA_8888.
06-05 13:45:39.671: D/AndroidRuntime(20800): Shutting down VM
06-05 13:45:39.671: W/dalvikvm(20800): threadid=1: thread exiting with uncaught exception (group=0x40e40360)
06-05 13:45:39.671: E/AndroidRuntime(20800): FATAL EXCEPTION: main
06-05 13:45:39.671: E/AndroidRuntime(20800): java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
06-05 13:45:39.671: E/AndroidRuntime(20800): at com.genebi.rubik.MainActivity$1.onItemClick(MainActivity.java:31)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.widget.AbsListView$1.run(AbsListView.java:3973)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.os.Handler.handleCallback(Handler.java:615)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.os.Handler.dispatchMessage(Handler.java:92)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.os.Looper.loop(Looper.java:137)
06-05 13:45:39.671: E/AndroidRuntime(20800): at android.app.ActivityThread.main(ActivityThread.java:4950)
06-05 13:45:39.671: E/AndroidRuntime(20800): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 13:45:39.671: E/AndroidRuntime(20800): at java.lang.reflect.Method.invoke(Method.java:511)
06-05 13:45:39.671: E/AndroidRuntime(20800): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
06-05 13:45:39.671: E/AndroidRuntime(20800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
06-05 13:45:39.671: E/AndroidRuntime(20800): at dalvik.system.NativeStart.main(Native Method)
this is wrong way for getting value from clicked item on listView:
String categoria = ((TextView) v).getText().toString();
as v is your row in list you can't cast that to TextView and get text from that,
you need use following code:
TextView c = (TextView) v.findViewById(R.id.TextViewID); // i think this is nombreCategoria
String categoria = c.getText().toString();
or you can use position for getting value from list, like following code:
String categoria = lista_categorias[position]
and another way is:
String categoria =(String) arg0.getItemAtPosition(position);

Categories