Cannot use android.support.v7.widget.DrawerLayout in Android - android

I am absolute beginner to Android. I start learning how to use action bar in android very well with navigation drawer. I already created a simple app using android.support.v4.widget.DrawerLayout layout in xml file.
It was working fine. But when I use android.support.v7.widget.DrawerLayout instead, it is throwing error. But when I changed it back to android.support.v4.widget.DrawerLayout,it is working fine.
This is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="#layout/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="#+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"/>
<!--app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_view" />-->
</android.support.v7.widget.DrawerLayout>
This is the action_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
</android.support.v7.widget.Toolbar>
This is my MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is the errors in logcat when I run it
01-29 11:22:43.026 20642-20642/? D/dalvikvm: Late-enabling CheckJNI
01-29 11:22:43.118 20642-20642/com.blog.waiyanhein.llks.llks W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks W/dalvikvm: VFY: unable to resolve interface method 17962: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks W/dalvikvm: VFY: unable to resolve interface method 17966: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-29 11:22:43.122 20642-20642/com.blog.waiyanhein.llks.llks D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-29 11:22:43.190 20642-20642/com.blog.waiyanhein.llks.llks D/AndroidRuntime: Shutting down VM
01-29 11:22:43.190 20642-20642/com.blog.waiyanhein.llks.llks W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa617d908)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: FATAL EXCEPTION: main
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blog.waiyanhein.llks.llks/com.blog.waiyanhein.llks.llks.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class android.support.v7.widget.DrawerLayout
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class android.support.v7.widget.DrawerLayout
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.blog.waiyanhein.llks.llks.MainActivity.onCreate(MainActivity.java:15)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5104)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.DrawerLayout" on path: /data/app/com.blog.waiyanhein.llks.llks-2.apk
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.createView(LayoutInflater.java:552)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.blog.waiyanhein.llks.llks.MainActivity.onCreate(MainActivity.java:15) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5104) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
01-29 11:22:43.210 20642-20642/com.blog.waiyanhein.llks.llks E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method) 
What is wrong with my code?

You're getting a ClassNotFoundException because there is no DrawerLayout class in the v7 appcompat library.
They did not update this particular widget, presumably because there wasn't really anything to improve upon functionally, nor anything visual that needed a makeover, as it's just an empty, transparent layout.
Other components that were updated - such as the ActionBarDrawerToggle class - are designed to work with the v4 support library version of DrawerLayout, and, in fact, the v7 library depends on the v4.
TL;DR - Just stick with the v4 DrawerLayout.

Instead of using v7 use v4. Change the
android.support.v7.widget.DrawerLayout
to
android.support.v4.widget.DrawerLayout
Will solve the issue.

Related

NoClassDefFoundError for socket.io on a background service when using multidex

I'm trying to create a background service that runs whenever my application is closed .The purpose of this service is to connect to a nodejs server and whenever an event occurs (via socket.io) it will notify the user .
However when i start my service my app crashes and i get the following error
01-06 16:52:14.239 2304-2304/? D/dalvikvm: Late-enabling CheckJNI
01-06 16:52:14.255 2304-2310/? D/dalvikvm: Debugger has detached; object registry had 1 entries
01-06 16:52:14.267 2304-2318/? W/SharedPreferencesImpl: Attempt to read preferences file /data/data/com.esprit.redcrescentapp/shared_prefs/RedCrecent.xml without permission
01-06 16:52:14.267 2304-2304/? D/Service: Created
01-06 16:52:14.267 2304-2304/? I/dalvikvm: Could not find method io.socket.client.IO.socket, referenced from method com.esprit.redcrescentapp.SocketHandler.<init>
01-06 16:52:14.267 2304-2304/? W/dalvikvm: VFY: unable to resolve static method 63105: Lio/socket/client/IO;.socket (Ljava/lang/String;)Lio/socket/client/Socket;
01-06 16:52:14.267 2304-2304/? D/dalvikvm: VFY: replacing opcode 0x71 at 0x0005
01-06 16:52:14.267 2304-2304/? I/dalvikvm: Could not find method io.socket.client.IO.socket, referenced from method com.esprit.redcrescentapp.SocketHandler.getSocketInstance
01-06 16:52:14.267 2304-2304/? W/dalvikvm: VFY: unable to resolve static method 63105: Lio/socket/client/IO;.socket (Ljava/lang/String;)Lio/socket/client/Socket;
01-06 16:52:14.267 2304-2304/? D/dalvikvm: VFY: replacing opcode 0x71 at 0x0006
01-06 16:52:14.267 2304-2304/? D/AndroidRuntime: Shutting down VM
01-06 16:52:14.267 2304-2304/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d0eb20)
01-06 16:52:14.267 2304-2304/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.esprit.redcrescentapp, PID: 2304
java.lang.NoClassDefFoundError: io.socket.client.IO
at com.esprit.redcrescentapp.SocketHandler.getSocketInstance(SocketHandler.java:100)
at com.esprit.redcrescentapp.MyService.onCreate(MyService.java:74)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2558)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
I think that this exception is thrown because of not adding MultiDex.install() in the MyService class but on the other whenever i try to add it i get another exception
01-06 17:05:43.499 7677-7677/? D/dalvikvm: Late-enabling CheckJNI
01-06 17:05:43.519 7677-7683/? D/dalvikvm: Debugger has detached; object registry had 1 entries
01-06 17:05:43.527 7677-7677/? I/MultiDex: VM with version 1.6.0 does not have multidex support
01-06 17:05:43.527 7677-7677/? I/MultiDex: install
01-06 17:05:43.527 7677-7677/? I/MultiDex: MultiDexExtractor.load(/data/app/com.esprit.redcrescentapp-2.apk, false)
01-06 17:05:43.531 7677-7690/? W/SharedPreferencesImpl: Attempt to read preferences file /data/data/com.esprit.redcrescentapp/shared_prefs/multidex.version.xml without permission
01-06 17:05:43.531 7677-7677/? I/MultiDex: Detected that extraction must be performed.
01-06 17:05:43.531 7677-7677/? E/MultiDex: Failed to create dir /data/data/com.esprit.redcrescentapp/code_cache/secondary-dexes. parent file is a dir true, a file false, exists true, readable false, writable false
01-06 17:05:43.531 7677-7677/? E/MultiDex: Multidex installation failure
java.io.IOException: Failed to create cache directory /data/data/com.esprit.redcrescentapp/code_cache/secondary-dexes
at android.support.multidex.MultiDexExtractor.mkdirChecked(MultiDexExtractor.java:301)
at android.support.multidex.MultiDexExtractor.prepareDexDir(MultiDexExtractor.java:261)
at android.support.multidex.MultiDexExtractor.performExtractions(MultiDexExtractor.java:170)
at android.support.multidex.MultiDexExtractor.load(MultiDexExtractor.java:102)
at android.support.multidex.MultiDex.install(MultiDex.java:159)
at com.esprit.redcrescentapp.MyService.attachBaseContext(MyService.java:217)
at android.app.Service.attach(Service.java:694)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2556)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
01-06 17:05:43.531 7677-7677/? D/AndroidRuntime: Shutting down VM
01-06 17:05:43.531 7677-7677/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d0eb20)
01-06 17:05:43.531 7677-7677/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.esprit.redcrescentapp, PID: 7677
java.lang.RuntimeException: Unable to create service com.esprit.redcrescentapp.MyService: java.lang.RuntimeException: Multi dex installation failed (Failed to create cache directory /data/data/com.esprit.redcrescentapp/code_cache/secondary-dexes).
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2568)
at android.app.ActivityThread.access$1800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
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.RuntimeException: Multi dex installation failed (Failed to create cache directory /data/data/com.esprit.redcrescentapp/code_cache/secondary-dexes).
at android.support.multidex.MultiDex.install(MultiDex.java:178)
at com.esprit.redcrescentapp.MyService.attachBaseContext(MyService.java:217)
at android.app.Service.attach(Service.java:694)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2556)
at android.app.ActivityThread.access$1800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
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) 
in my manifest i had
<service
android:enabled="true"
android:isolatedProcess="true"
/>
once i removed enabled and isolatedProcess it worked

ViewPagerIndicator library doesn't work in 4.4

I am using viewpagerindicator library for circle indicator and it works great on 5.0(Lolipop), 6.0(Marshmallow) but it crashes on 4.4(Kitkat).I've tried using dependency based on module by adding library project and using following option but none of them works on 4.4
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1'
Here's the log.
2-29 18:27:22.992 32182-32182/com.kicksexchange D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0177
12-29 18:27:22.992 32182-32182/com.kicksexchange I/dalvikvm﹕ Could not find method com.viewpagerindicator.CirclePageIndicator.setViewPager, referenced from method com.kicksexchange.fragments.ProductDetail.updateUI
12-29 18:27:23.002 32182-32182/com.kicksexchange W/dalvikvm﹕ VFY: unable to resolve virtual method 62723: Lcom/viewpagerindicator/CirclePageIndicator;.setViewPager (Landroid/support/v4/view/ViewPager;)V
12-29 18:27:23.002 32182-32182/com.kicksexchange D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0271
12-29 18:27:23.072 32182-32182/com.kicksexchange D/ProductDetail﹕ onCreate Product Detail Fragment
12-29 18:27:23.072 32182-32182/com.kicksexchange D/ProductDetail﹕ 205
12-29 18:27:23.072 32182-32182/com.kicksexchange D/ProductDetail﹕ Nike Sports Shoes
12-29 18:27:23.192 32182-32182/com.kicksexchange D/AndroidRuntime﹕ Shutting down VM
12-29 18:27:23.192 32182-32182/com.kicksexchange W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x42046d58)
12-29 18:27:23.242 32182-32182/com.kicksexchange E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.kicksexchange, PID: 32182
android.view.InflateException: Binary XML file line #122: Error inflating class com.viewpagerindicator.CirclePageIndicator
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.kicksexchange.fragments.ProductDetail.onCreateView(ProductDetail.java:152)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
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:5050)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.viewpagerindicator.CirclePageIndicator" on path: DexPathList[[zip file "/data/app/com.kicksexchange-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.kicksexchange-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.kicksexchange.fragments.ProductDetail.onCreateView(ProductDetail.java:152)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
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:5050)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)

findViewById on an ImageView why does setBackgroundColor give NullPointerException

I have a very basic activity with an ImageView of android:id="#+id/imageViewTest"
and then in the OnCreate method calling:
ImageView imageView = (ImageView)findViewById(R.id.imageViewTest);
// Set the background color to white
imageView.setBackgroundColor(Color.WHITE);
this gives error:
10-15 16:36:27.552 29097-29097/org.explore.self.beginner D/dalvikvm﹕ Late-enabling CheckJNI
10-15 16:36:28.017 29097-29097/org.explore.self.beginner D/AndroidRuntime﹕ Shutting down VM
10-15 16:36:28.017 29097-29097/org.explore.self.beginner W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d9b2a0)
10-15 16:36:28.042 29097-29097/org.explore.self.beginner E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.explore.self.beginner/org.selfexplore.android.view.activity.TestActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.selfexplore.android.view.activity.TestActivity.onCreate(TestActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5188)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
            at android.app.ActivityThread.access$700(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4921)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
            at dalvik.system.NativeStart.main(Native Method)
10-15 16:36:28.062 29097-29097/org.explore.self.beginner I/Process﹕ Sending signal. PID: 29097 SIG: 9
But when I do a
ImageView imageView = new ImageView(this);
it works fine, Why?
PS: I am not able to add the layout code here, so sharing it in this doc: https://docs.google.com/document/d/1fbi3B_hAYUh_C2IwPfInvZ-BG2bgsa4pZoJKj8NBT9o/edit?usp=sharing
Your layout you've set with setContentView() doesn't have a view with id imageViewTest and findViewById() returns null, or you haven't called setContentView() at all.

Android Closing My Application Without Any Notification

I am working on Card Scanner application, Using native camera and barcode scanning apis in my app(everything is fine with camera and barcode sanning), also using Spring Android library with Java POJO Objects for in/out to Rest apis.
ISSUE
Android is closing my application without any notification, QA reported a bug that he was testing and suddenly app closed(behavior is similar to home button press).
I don't have any idea about this issue. I reproduced this issue at my end and got below mentioned logs in logcat.
Here is my logs:
01-29 14:35:00.805: E/AndroidRuntime(25696): FATAL EXCEPTION: main
01-29 14:35:00.805: E/AndroidRuntime(25696): Process: com.ihi.bcr, PID: 25696
01-29 14:35:00.805: E/AndroidRuntime(25696): java.lang.RuntimeException: Unable to start service com.ihi.bcr.services.ContactSyncService#44e4fbf8 with Intent { flg=0x10000000 cmp=com.ihi.bcr/.services.ContactSyncService }: java.lang.NullPointerException
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2719)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.access$2100(ActivityThread.java:135)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.os.Handler.dispatchMessage(Handler.java:102)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.os.Looper.loop(Looper.java:136)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-29 14:35:00.805: E/AndroidRuntime(25696): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 14:35:00.805: E/AndroidRuntime(25696): at java.lang.reflect.Method.invoke(Method.java:515)
01-29 14:35:00.805: E/AndroidRuntime(25696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-29 14:35:00.805: E/AndroidRuntime(25696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-29 14:35:00.805: E/AndroidRuntime(25696): at dalvik.system.NativeStart.main(Native Method)
01-29 14:35:00.805: E/AndroidRuntime(25696): Caused by: java.lang.NullPointerException
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.IntentService.onStart(IntentService.java:116)
01-29 14:35:00.805: E/AndroidRuntime(25696): at roboguice.service.RoboIntentService.onStart(RoboIntentService.java:66)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.IntentService.onStartCommand(IntentService.java:130)
01-29 14:35:00.805: E/AndroidRuntime(25696): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2702)
01-29 14:35:00.805: E/AndroidRuntime(25696): ... 10 more
01-29 14:35:00.815: W/ActivityManager(780): Force finishing activity com.ihi.bcr/.activity.HomeScreen
01-29 14:35:00.975: E/Database(19015): 0
01-29 14:35:01.185: E/Database(19015): 0
01-29 14:35:01.215: D/audio_hw_primary(184): select_devices: out_snd_device(2: speaker) in_snd_device(0: )
01-29 14:35:01.345: W/ActivityManager(780): Activity pause timeout for ActivityRecord{4382e1c0 u0 com.ihi.bcr/.activity.HomeScreen t171 f}
01-29 14:35:01.405: E/Database(19015): 0
01-29 14:35:01.645: D/dalvikvm(19015): GC_FOR_ALLOC freed 527K, 4% free 17113K/17728K, paused 24ms, total 25ms
NOTE:
ContactSyncService is intent service.
I am starting contactSyncService by startService() method.
I didn't override onStart and onStartCommand() functions of IntentService(As it is mention in Android Docs)
You have missed to call super.onCreate() in your ContactSyncService.onCreate().

Spinner on an ActionBar issue on a Dialog Activity

Hi I have an activity that shows a dialog form an standard layout.
android:theme="#android:style/Theme.Holo.Light.Dialog"/>
I was trying to add a simple spinner to the actionbar but I am having issues and error in the line getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST).
When I change my theme to a common activity it works perfect.
This are the errors showed by the logcat:
3114-3114/org.PeteProto E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.PeteProto/org.PeteProto.Detail}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.PeteProto.Detail.onCreate(Detail.java:30)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more

Categories

Resources