Android App crash, can't figure out the issue [duplicate] - android

This question already has answers here:
Getting android.content.res.Resources$NotFoundException: exception even when the resource is present in android
(16 answers)
Closed 4 years ago.
I have 2 phones, 1 samsung S8 running v8.0 and a LG G4 running v6.0. I have both plugged into the same computer and build the app and run it on the phones. All seems good on the Samsung, and all installs and seems good on the LG until I press the menu button on the first Activity.
My first activity loads a fragment which puts the 3 dot menu in the top right. I only have 1 item in the menu which opens a new activity that has a list of items to select from. On the LG when this 3 dot menu is pressed, the app crashes, but on the S8, it opens the menu and allows me to select the 1 item and open the next activity.
Looking for any ideas on where to go with this.
The Error I get:
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
I/AudioManagerEx: AudioManagerEx created
I/ListPopupWindow: Could not find method setEpicenterBounds(Rect) on PopupWindow. Oh well.
W/ResourceType: Failure getting entry for 0x7f07013a (t=6 e=314) (error -75)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.czdev.booktimeline, PID: 15910
android.content.res.Resources$NotFoundException: Resource ID #0x7f07013a
at android.content.res.Resources.getValue(Resources.java:1401)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425)
at android.support.v7.view.menu.ListMenuItemView.initialize(ListMenuItemView.java:116)
at android.support.v7.view.menu.MenuAdapter.getView(MenuAdapter.java:100)
at android.support.v7.view.menu.MenuPopup.measureIndividualMenuWidth(MenuPopup.java:160)
at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:153)
at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187)
at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290)
at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175)
at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:803)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Application terminated.
Here is my Gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.oss.licenses.plugin'
android {
compileSdkVersion 27
defaultConfig {
applicationId "<com.android.application>"
minSdkVersion 21
targetSdkVersion 27
versionCode 25
versionName "0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-oss-licenses:15.0.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
repositories {
mavenCentral()
}
Here is my first fragment:
public class HomeFrag extends Fragment {
View rootView;
public HomeFrag() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_home, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.app_name);
((MainActivity) Objects.requireNonNull(getActivity())).setSupportActionBar(toolbar);
setHasOptionsMenu(true);
return rootView;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.menu_action_info) {
startActivity(new Intent(getContext(), InfoMenu.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/menu_action_info"
android:icon="#drawable/ic_info_outline_white_24dp"
android:orderInCategory="100"
android:title="#string/menu_info_action"
app:showAsAction="never" />
</menu>
Any ideas would be great.

From the crash logs , it seems its failing to load the icon
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:425)
Can you please check your R.java for Resource ID #0x7f07013a , it will tell you exactly which resource is failing to load, my guess is the icon is missing in a particular drawable folder.
Ankit

Related

Menu item not visible in Fragment

I would like to show a menu in my fragment. I've done this a million times, yet it is not working now for some reason. This is the first time I experiment with the new androidx library, maybe bug?
Fragment:
public class FragmentDogs extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dogs, container, false);
setHasOptionsMenu(true);
return rootView;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_dogs, menu);
}
}
Activity:
public class ActivityMain extends AppCompatActivity {
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new FragmentDogs()).commit();
}
}
Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/dogs_add_menu_item"
android:icon="#drawable/ic_plus"
android:title="#string/dogs" />
Gradle:
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.platinum"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Screenshot:
You have to set the custom toolbar to the Fragment Layout and as SupportActionBar.
Your Fragment Layout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:elevation="5dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="50dp"
app:contentInsetRight="50dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:title="testtext"
app:contentInsetStartWithNavigation="0dp">
</android.support.v7.widget.Toolbar>
Your Fragment class
public class YourFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.yourfragmentlayout, container, false);
setHasOptionsMenu(true);
Toolbar toolbar = (Toolbar)rootView.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("YourFragment");
return rootView;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_dogs, menu);
super.onCreateOptionsMenu(menu, inflater);
}
}
If YourFragment() is red underlined
Make sure that you are using
import android.support.v4.app.Fragment;
instead of
import android.app.Fragment;
you are missing the closing tag on menu.xml, which possibly should end with </menu>.
the testInstrumentationRunner is not the correct test-runner for androidx, along with the other test dependencies. androidx.fragment:fragment:1.0.0 would be the proper dependency for the Fragment class. see the migration guide for further androidx dependencies, which you might be lacking; alike androidx.appcompat:appcompat:1.0.2 for the AppCompatActivity.
it might be a X/Y problem... first fix the dependencies - and then the menu.

AppCompatImageButton cannot be cast to android.widget.Button even though it's not an ImageButton

I'm getting an error that I can't understand:
07-19 22:14:50.750 23192-23192/com.example.shun.zeatbeta E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shun.zeatbeta, PID: 23192
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shun.zeatbeta/com.example.shun.zeatbeta.ReauthenticateActivity}: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageButton cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageButton cannot be cast to android.widget.Button
at com.example.shun.zeatbeta.ReauthenticateActivity.onCreate(ReauthenticateActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6942)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 
at android.app.ActivityThread.-wrap14(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 
Line that crashes program in activity:
private Button loginButton;
loginButton = (Button) findViewById(R.id.loginButton);
activity_reauthenticate2.xml:
<com.example.shun.zeatbeta.ComfortaaButton
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="#dimen/button_height"
android:layout_marginTop="20dp"
android:background="#drawable/round_button_blue"
android:text="#string/login"
android:textColor="#color/white"
android:textSize="15dp"
app:layout_constraintBottom_toTopOf="#id/facebookWrapper"
app:layout_constraintTop_toBottomOf="#id/textFields" />
ComfortaaButton.java
package com.example.shun.zeatbeta;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;
public class ComfortaaButton extends AppCompatButton {
public ComfortaaButton(Context context) {
super(context);
init();
}
public ComfortaaButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ComfortaaButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public void init() {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/Comfortaa-Regular.ttf");
setTypeface(tf, 1);
}
}
Why am I getting this error? The button is clearly a Button, not an ImageButton. I've tried cleaning project, restarted, clearing cache, etc. I even tried creating a new activity and layout file, and the error came back!
UPDATE: I got this info for the line in activity crashing the code:
Unexpected cast to AppCompatButton: layout tag was ImageButton (Id bound to an ImageButton in activity_landing_page.xml) less... (⌘F1)
Keeps track of the view types associated with ids and if it finds a usage of the id in the Java code it ensures that it is treated as the same type.
So it seems like it looks for activities by id in activity_landing_page.xml instead of in activity_reauthenticate2.xml. Why? How can I change that?
the app gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.example.s.company"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:support-v4:27.1.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.facebook.android:facebook-android-sdk:4.33.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.stripe:stripe-android:6.1.2'
compile 'com.google.firebase:firebase-auth:15.0.0'
compile 'com.google.firebase:firebase-core:15.0.0'
compile 'com.google.firebase:firebase-database:15.0.0'
compile 'com.google.firebase:firebase-storage:15.0.0'
compile 'com.firebaseui:firebase-ui-storage:3.3.1'
compile 'com.android.volley:volley:1.1.0'
compile 'com.felipecsl.asymmetricgridview:library:2.0.1'
compile 'com.google.android.gms:play-services-maps:15.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.github.ittianyu:BottomNavigationViewEx:1.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0'
compile 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'info.hoang8f:android-segmented:1.0.6'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
There must be are other duplicate id for your loginButton. Just make sure that you will get the correct import when you type R.id.loginButton from loginButton = (Button) findViewById(R.id.loginButton); for your target Activity or xml.
Update:
Button should also work fine.
Initiating the view as AppCompatButton,
private AppCompatButton mLoginButton;
mLoginButton=findViewById(R.id.loginButton);
//This error occured when I mistakenly coded
val deleteButton = itemView.findViewById<(Button)>(R.id.item_delete_button)
//Actually in the XML file I used a Image View instead of a Button to make that image //clickable.
// So I changed the <(Button)> to <(ImageView)>. Then this problem was resolved.

(Android Butterknife) how to change text on button after clicking

I have a button and I want to change text on it after it was clicked.
#BindView(R.id.btn) Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
#OnClick(R.id.btn)
public void click()
{
btn.setText("anything");
}
I've realized that I can do this with normal onclickListener, but I am wondering if I can do this using butterknife.
EDIT
Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.jnx.test"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
EDIT
Error log
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jnx.test/com.jnx.test.MainActivity}: java.lang.IllegalStateException: Required view 'btn' with ID 2131427422 for field 'btn' and method 'click' was not found. If this view is optional add '#Nullable' (fields) or '#Optional' (methods) annotation.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: Required view 'btn' with ID 2131427422 for field 'btn' and method 'click' was not found. If this view is optional add '#Nullable' (fields) or '#Optional' (methods) annotation.
at butterknife.internal.Utils.findRequiredView(Utils.java:92)
at com.jnx.test.MainActivity_ViewBinding.<init>(MainActivity_ViewBinding.java:29)
at java.lang.reflect.Constructor.newInstance(Native Method)
at butterknife.ButterKnife.createBinding(ButterKnife.java:199)
at butterknife.ButterKnife.bind(ButterKnife.java:124)
at com.jnx.test.MainActivity.onCreate(MainActivity.java:22)
Line 22 in MainActivity is setContentView(R.layout.activity_main);
Ok, I got it. I think someone have posted such answer before, but it didn't worked for me at first. It started working after the restart of android studio.
#BindView(R.id.btn) Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
#OnClick(R.id.btn)
public void click(View v)
{
btn.setText("dsdssd");
}
You have to pass the View as an argument.
You can pass the view :
#OnClick(R.id.btn)
public void click(Button button) {
button.setText("Hello");
}
And you don't need this line so remove this:
#BindView(R.id.btn) Button btn;

Implementing ButterKnife giving NullPointer Exception

I'm trying to implement the ButterKnife library in a small project, how ever my app crashes when it starts, details:
here is my MainActivity.java :
package com.example.odai.playwithme;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
#BindView(R.id.hello_world) TextView hello;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
hello.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Hello",
Toast.LENGTH_SHORT).show();
}
});
}
}
my 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"
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="com.example.odai.playwithme.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/hello_world"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
my build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.odai.playwithme"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.jakewharton:butterknife:8.0.1'
}
and this is the error I get whenever I try to run my app :
05-22 20:32:52.019 24076-24076/com.example.odai.playwithme E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.odai.playwithme, PID: 24076
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.odai.playwithme/com.example.odai.playwithme.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2484)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.example.odai.playwithme.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544) 
at android.app.ActivityThread.access$900(ActivityThread.java:150) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:168) 
at android.app.ActivityThread.main(ActivityThread.java:5845) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
any ideas?
I had this problem a while back, too, and actually just tried again to see if it was just a one time thing. Apparently the newer ButterKnife requires a bit more stuff in your build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
}
(https://github.com/JakeWharton/butterknife)
Remove #Bindview line and do the following to bind elements properly:
Click on your layout name in setContentView line
Press alt+enter , it will bring insert options
Click generate butterknief injections
Choose elements that you want to bind
Click ok.
And it will work.
You can also set onclick events directly from there while choosing the views to bind.

Android Fresco: Error inflating class com.facebook.samples.zoomable.ZoomableDraweeView

I want to create application using Fresco library with zoom functionality using ZoomableDraweeView but when I start my application, application got crashed. Below is my code so please help me to solve this issue and thanks in advance.
public class ZoomActivity extends Activity {
private ZoomableDraweeView view;
private DraweeController ctrl;
private GenericDraweeHierarchy hierarchy;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Fresco.initialize(this);
setContentView(R.layout.activity_zoom);
Uri imageUri = Uri.parse("http://i.imgur.com/76Jfv9b.jpg");
view = (ZoomableDraweeView) findViewById(R.id.zoomable);
ctrl = Fresco.newDraweeControllerBuilder().setUri(imageUri).setTapToRetryEnabled(true).build();
hierarchy = new GenericDraweeHierarchyBuilder(getResources())
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
.setProgressBarImage(new ProgressBarDrawable())
.build();
view.setController(ctrl);
view.setHierarchy(hierarchy);
}
}
Here is my layout.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.imageloaderexample.Activity.Fresco.ZoomActivity">
<com.facebook.samples.zoomable.ZoomableDraweeView
android:id="#+id/zoomable"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Here is Gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.android.imageloaderexample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile files('libs/picasso-2.5.2.jar')
compile files('libs/universal-image-loader-1.9.5.jar')
compile files('libs/glide-3.6.1.jar')
compile 'com.facebook.fresco:fresco:0.10.0'
compile 'com.facebook.fresco:animated-gif:0.10.0'
compile "com.facebook.fresco:imagepipeline-okhttp:0.10.0+"
}
Below is my logcate.
FATAL EXCEPTION: Process: com.example.android.imageloaderexample, PID:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.imageloaderexample/com.example.android.imageloaderexample.Activity.Fresco.ZoomActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.facebook.samples.zoomable.ZoomableDraweeView
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)... 23 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack availableBB
<com.example.android.imageloaderexample.Activity.ZoomableDraweeView
android:id="#+id/zoomable"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Please add this Code It is working for me and Enjoy .. . !!

Categories

Resources