Force close after clear memory and resume app - java

When I test my app, after close app and clean memory(in my case, CleanMaster app) and then reopen it again, it force close. I try search for cause but can't find solvable solution.
It work all fine if not clean memory. I wonder if anything need to be saved and restore after these incident. I'm quite newby for Android.
here is log
06-29 11:59:19.479 22283-22283/com.thaifasttel D/WebView﹕ onTrimMemory: 20
06-29 11:59:33.985 22524-22524/com.thaifasttel D/jdwp﹕ sendBufferedRequest : len=0x39
06-29 11:59:33.993 22524-22524/com.thaifasttel W/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
06-29 11:59:34.050 22524-22524/com.thaifasttel D/dalvikvm﹕ newInstance failed: no <init>()
06-29 11:59:34.052 22524-22524/com.thaifasttel D/AndroidRuntime﹕ Shutting down VM
06-29 11:59:34.052 22524-22524/com.thaifasttel W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40d6f9a8)
06-29 11:59:34.060 22524-22524/com.thaifasttel E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thaifasttel/com.thaifasttel.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.thaifasttel.MainActivity$PlaceholderFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.thaifasttel.MainActivity$PlaceholderFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:413)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1801)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:97)
at com.thaifasttel.MainActivity.onCreate(MainActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5371)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.thaifasttel.MainActivity$PlaceholderFragment; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
            at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
            at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1801)
            at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:97)
            at com.thaifasttel.MainActivity.onCreate(MainActivity.java:73)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
            at android.app.ActivityThread.access$600(ActivityThread.java:162)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5371)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.e("My App", "onCreateView");
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
WebView myWebView;
RelativeLayout splash_view;
TextView splash_text;
SharedPreferences Usettings;
String lang="th";
int isloadwa=0;
AssetManager assetPath = getAssets();
String waAssetPath ="web";
String wabase=getApplicationContext().getFilesDir().getPath();
String waIntPath = "web";
String waIntPath2 = wabase+"/"+waIntPath;
String baseupdatefolder="http://www.test.com/test/webapp";
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.e("My App", "onActivityCreated");
myWebView = (WebView) getView().findViewById(R.id.webview);
splash_view = (RelativeLayout) getView().findViewById(R.id.splashview);
splash_text = (TextView) getView().findViewById(R.id.splash_status);
inituserPref();
copydir();
}
#Override
public void onStart(){
super.onStart();
Log.e("My App", "onstart");
}
#Override
public void onResume(){
super.onResume();
Log.e("My App", "onResume");
if(isloadwa==1) {
if (isConnected()) {
Log.e("My App", "check update in app");
splash_text.setText(a_check_update);
checkupdate();
}
}
}
// do a lot of method after this

Related

Cannot locate all audio files to store in list view

so I am having trouble locating where in my code I have gone wrong. I am building an audio player. The function cannot find all audio files in my device except 2 of them. I am thinking the problem may lie somewhere in my song locating algorithm, findSongs.
Here is my log cat:
03-17 15:29:24.492 20066-20066/? I/SELinux﹕ Function: selinux_android_load_priority , priority [3] , priority version is VE=SEPF_SGH-M919_4.4.4_0048
03-17 15:29:24.492 20066-20066/? E/dalvikvm﹕ >>>>> Normal User
03-17 15:29:24.492 20066-20066/? E/dalvikvm﹕ >>>>> com.example.joe.audiodomain [ userId:0 | appId:10237 ]
03-17 15:29:24.492 20066-20066/? D/dalvikvm﹕ Late-enabling CheckJNI
03-17 15:29:24.632 20066-20066/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
03-17 15:29:24.632 20066-20066/? I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
03-17 15:29:24.632 20066-20066/? W/dalvikvm﹕ VFY: unable to resolve interface method 15027: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
03-17 15:29:24.632 20066-20066/? D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
03-17 15:29:24.632 20066-20066/? I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
03-17 15:29:24.632 20066-20066/? W/dalvikvm﹕ VFY: unable to resolve interface method 15031: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
03-17 15:29:24.632 20066-20066/? D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
03-17 15:29:24.702 20066-20066/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
03-17 15:29:24.702 20066-20066/? W/dalvikvm﹕ VFY: unable to resolve virtual method 396: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-17 15:29:24.702 20066-20066/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-17 15:29:24.702 20066-20066/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
03-17 15:29:24.702 20066-20066/? W/dalvikvm﹕ VFY: unable to resolve virtual method 418: Landroid/content/res/TypedArray;.getType (I)I
03-17 15:29:24.702 20066-20066/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-17 15:29:24.712 20066-20066/? E/VdcInflateDelegate﹕ Exception while inflating <vector>
org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:535)
at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:472)
at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:436)
at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:829)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:303)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.example.joe.audiodomain.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5585)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.access$900(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
03-17 15:29:24.712 20066-20066/? D/AndroidRuntime﹕ Shutting down VM
03-17 15:29:24.712 20066-20066/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41845da0)
03-17 15:29:24.712 20066-20066/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.joe.audiodomain, PID: 20066
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.joe.audiodomain/com.example.joe.audiodomain.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
at android.app.ActivityThread.access$900(ActivityThread.java:170)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5635)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
at com.example.joe.audiodomain.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5585)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
            at android.app.ActivityThread.access$900(ActivityThread.java:170)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5635)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            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:600)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
            at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
            at com.example.joe.audiodomain.MainActivity.onCreate(MainActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:5585)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
            at android.app.ActivityThread.access$900(ActivityThread.java:170)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5635)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v19/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
at android.content.res.Resources.loadDrawable(Resources.java:3439)
at android.content.res.Resources.getDrawable(Resources.java:1893)
at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
            at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
            at com.example.joe.audiodomain.MainActivity.onCreate(MainActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:5585)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
            at android.app.ActivityThread.access$900(ActivityThread.java:170)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5635)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
at android.content.res.Resources.loadDrawable(Resources.java:3435)
            at android.content.res.Resources.getDrawable(Resources.java:1893)
            at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
            at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
            at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
            at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
            at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
            at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
            at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:600)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
            at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
            at com.example.joe.audiodomain.MainActivity.onCreate(MainActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:5585)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
            at android.app.ActivityThread.access$900(ActivityThread.java:170)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5635)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
03-17 15:29:31.839 20066-20066/? I/Process﹕ Sending signal. PID: 20066 SIG: 9
Here is my code:
`
package com.example.joe.mp3demo;
import android.app.Activity;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ListActivity extends Activity {
ListView lv;
ArrayAdapter<String> adapter;
String songs[];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
//Creating a List view instance
lv= (ListView) findViewById(R.id.listView);
//Array list to hold all songs, using findSongs method passing the SD card directory
ArrayList<File> allSongs= findSongs(Environment.getExternalStorageDirectory());
songs= new String[allSongs.size()];
for(int c=0; c< allSongs.size(); c++){
songs[c]=allSongs.get(c).getName().toString();
}
adapter= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songs);
lv.setAdapter(adapter);
}
//function to find all songs in SD card. Storing them in a temp ArrayList and returning
public ArrayList<File> findSongs(File root){
ArrayList<File> al= new ArrayList<File>();
File[] files=root.listFiles();
for(File singleFile: files){
if(singleFile.isDirectory() && !singleFile.isHidden()) {
al.addAll(findSongs(singleFile));
}
else{
if(singleFile.getName().endsWith(".mp3") || singleFile.getName().endsWith(".wav") || singleFile.getName().endsWith(".wma") ){
al.add(singleFile);
}
}
}
return al;
}
#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_list, 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);
}
}
Try this code:-
public class FindMp3Files extends AppCompatActivity {
ListView mp3List;
String title, artist, path, displayName, songDuration;
ArrayList<Mp3Model> songs;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_mp3_files);
mp3List = (ListView) findViewById(R.id.mp3List);
songs = new ArrayList<>();
scanSdcard();
SongAdapter adapter = new SongAdapter(this, songs);
mp3List.setAdapter(adapter);
}
private void scanSdcard() {
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = {
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION
};
final String sortOrder = MediaStore.Audio.AudioColumns.TITLE + " COLLATE LOCALIZED ASC";
Cursor cursor = null;
try {
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
cursor = this.getContentResolver().query(uri, projection, selection, null, sortOrder);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Mp3Model mp3Model = new Mp3Model();
title = cursor.getString(0);
artist = cursor.getString(1);
path = cursor.getString(2);
displayName = cursor.getString(3);
songDuration = cursor.getString(4);
mp3Model.setTitle(title);
mp3Model.setArtist(artist);
mp3Model.setPath(path);
mp3Model.setDisplayName(displayName);
mp3Model.setSongDuration(songDuration);
songs.add(mp3Model);
cursor.moveToNext();
}
}
} catch (Exception e) {
Log.e("Tag", e.toString());
} finally {
if (cursor != null) {
cursor.close();
}
}
}
}
Here is the Mp3Model class :-
public class Mp3Model {
String title, artist, path, displayName, songDuration;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getSongDuration() {
return songDuration;
}
public void setSongDuration(String songDuration) {
this.songDuration = songDuration;
}
}
SongAdapter.java
public class SongAdapter extends BaseAdapter {
Context context;
ArrayList<Mp3Model> mp3Models;
LayoutInflater inflater;
Typeface captureFont;
public SongAdapter(Context context, ArrayList<Mp3Model> mp3Models) {
this.context = context;
this.mp3Models = mp3Models;
inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
captureFont = Typeface.createFromAsset(this.context.getAssets(), "fonts/Montserrat.ttf");
}
#Override
public int getCount() {
return mp3Models.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public class ViewHolder {
TextView songName;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
vh = new ViewHolder();
convertView = inflater.inflate(R.layout.song_row, parent, false);
vh.songName = (TextView) convertView.findViewById(R.id.songName);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
vh.songName.setText(mp3Models.get(position).getTitle());
vh.songName.setTypeface(captureFont);
vh.songName.setPadding(10, 10, 10, 10);
vh.songName.setTextColor(Color.WHITE);
vh.songName.setBackgroundColor(Color.parseColor("#333333"));
vh.songName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
return convertView;
}
}

Android Application java lang exception

I have created an android application using Android Studio IDE while clicking the button in my app it does'nt navigate it to the another activity instead its throwing up the exception
Here is My Logcat:
02-10 11:33:56.030 7404-7404/com.example.mcs.oodoeg E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
at android.view.View.performClick(View.java:4275)
at android.view.View$PerformClick.run(View.java:17434)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
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.ExceptionInInitializerError
at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
            at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
            at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
            at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
            at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
            at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
            at android.view.View.performClick(View.java:4275)
            at android.view.View$PerformClick.run(View.java:17434)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:177)
            at android.app.ActivityThread.main(ActivityThread.java:4947)
            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.NoClassDefFoundError: org.apache.ws.commons.serialize.DOMSerializer
at org.apache.xmlrpc.serializer.NodeSerializer.<clinit>(NodeSerializer.java:30)
            at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
            at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
            at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
            at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
            at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
            at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
            at android.view.View.performClick(View.java:4275)
            at android.view.View$PerformClick.run(View.java:17434)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:177)
            at android.app.ActivityThread.main(ActivityThread.java:4947)
            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)
This is my Main Activity class i have created two buttons here called register and signin:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn;
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intObj = new Intent(MainActivity.this,MainActivity2.class);
startActivity(intObj);
}
});
Button btn2;
btn2=(Button) findViewById(R.id.button2);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent= new Intent(MainActivity.this,Sigin.class);
startActivity(intent);
}
} );
}
When the register button is clicked this Main Activity2 should be called:
public class MainActivity2 extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
}
When sigin button is clicked this sigin class should be called:
public class Sigin extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sigin);
}
}
I think you are missing ws-commons-util-1.0.2.jar from $EXIST_HOME/lib/core.
You have to make sure you have included at least all of the libraries from $EXIST_HOME/lib/core.

ANDROID JAVA: Activity doesn't start when the used SharedPreferences

I have a problem. I want to read value Integer of activity "Settings" in the service GPSTracker and use it there. I use this SharedPrefrences and confirming key input. If the data is validated that the application returns to class FullscreenActivity.
This is the code responsible for this in activity Settings:
SharedPreferences.Editor editor;
public static final String NAME = "DISTANCE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
SharedPreferences pref = getApplicationContext().getSharedPreferences(NAME, MODE_PRIVATE);
editor=pref.edit();
Edit1= (EditText) findViewById(R.id.editSkan);
accept= (Button) findViewById(R.id.buttonSkan);
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (!Edit1.getText().toString().equals(""))
value = Integer.parseInt(Edit1.getText().toString());
editor.putInt("settings", value);
editor.commit();
Toast.makeText(getApplicationContext(), "Changed, value + " m", Toast.LENGTH_SHORT).show();
finish();
}
});
A code in GPSTracker like this:
SharedPreferences pref;
(...)
private int downloadSettings()
{
pref=context.getSharedPreferences("DISTANCE", Activity.MODE_PRIVATE);
value = pref.getInt("settings",15);
return value;
}
and a method call:
int dist = downloadSettings();
When I run the apps I get two errors in the log:
*java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adam.mobileproject/com.example.adam.mobileproject.FullscreenActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
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.NullPointerException
at com.example.adam.mobileproject.GPSTracker.downloadSettings(GPSTracker.java:284)
at com.example.adam.mobileproject.GPSTracker.<init>(GPSTracker.java:200)
at com.example.adam.mobileproject.FullscreenActivity.onCreate(FullscreenActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            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)*
PLEASE HELP!!!
The problem is definitely that context is null.
However, just like the Activity class, the Service class extends Context, so you should be able to replace context with this or getApplicationContext().
Try this:
private int downloadSettings()
{
pref = getApplicationContext().getSharedPreferences("DISTANCE", Activity.MODE_PRIVATE);
value = pref.getInt("settings",15);
return value;
}

Passing ArrayList<String> from activity to fragment in android

I have been dealing with an issue for a while now that I cannot seem to figure out, I am trying to pass an ArrayList<String> from an activity to a fragment, however, I get the following stack trace when I run the code
03-30 19:26:38.465 28955-28955/org.tcnjteamandroid.cryptochat E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: org.tcnjteamandroid.cryptochat, PID: 28955
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.tcnjteamandroid.cryptochat/org.tcnjteamandroid.cryptochat.drawer}: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2299)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5240)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at org.tcnjteamandroid.cryptochat.drawer.onCreate(drawer.java:53)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5240)
            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:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.ArrayList android.os.Bundle.getStringArrayList(java.lang.String)' on a null object reference
at org.tcnjteamandroid.cryptochat.NavigationDrawerFragment.onCreateView(NavigationDrawerFragment.java:96)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:920)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1206)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2159)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297)
at android.support.v7.app.ActionBarActivity.onCreateView(ActionBarActivity.java:547)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
            at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
            at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
            at org.tcnjteamandroid.cryptochat.drawer.onCreate(drawer.java:53)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2252)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2361)
            at android.app.ActivityThread.access$800(ActivityThread.java:145)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5240)
            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:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
the code I am using to pass this information and pick it up is as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
ArrayList<String> menuItems = new ArrayList<String>();
menuItems.add("Test");
Bundle bundle = new Bundle();
bundle.putStringArrayList("edttext", menuItems);
/* set Fragmentclass Arguments */
NavigationDrawerFragment fragobj = new NavigationDrawerFragment();
fragobj.setArguments(bundle);
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
And the code I am using to pick up the new arguments is:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ArrayList<String> strtext = getArguments().getStringArrayList("edttext");
mDrawerListView = (ListView) inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
strtext));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
return mDrawerListView;
}
Any help I could get would be greatly appreciated!
you can use a class with static ArrayList property
public class Values
{
public static ArrayList<String> myArrayList;
}
in the activity:
ArrayList<String> menuItems = new ArrayList<String>();
Values.myArrayList = menuItems;
in the fragment
ArrayList<String> strtext = Values.myArrayAdapter;

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo, all activities are registered in AndroidManifest.xml, dont know whats wrong

I'm new to Android and i'm trying to run an app (simple test app), but get this error(. I have registered all my activities in AndroidManifest.xml and i'm using Android Studio 1.0.2
Here is the logcat of an app:
01-03 20:34:24.128 17300-17300/com.example.temur.sherlocked D/AndroidRuntime﹕ Shutting down VM
01-03 20:34:24.134 17300-17300/com.example.temur.sherlocked E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.temur.sherlocked, PID: 17300
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.temur.sherlocked/com.example.temur.sherlocked.MainActivity}: java.lang.InstantiationException: com.example.temur.sherlocked.MainActivity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2124)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
Caused by: java.lang.InstantiationException: com.example.temur.sherlocked.MainActivity
at java.lang.Class.newInstance(Class.java:1561)
at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1559)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:1892)
at com.example.temur.sherlocked.MainActivity.<init>(MainActivity.java:43)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1559)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1084)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5086)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
Code of MainActivity
package com.example.temur.sherlocked;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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);
}
TextView infoTextView = (TextView)findViewById(R.id.textViewAnswer);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode,resultCode,data);
if (requestCode==CHOOSE_THIEF){
if (resultCode==RESULT_OK){
String thiefName = data.getStringExtra(SecondActivity.THIEF);
infoTextView.setText(thiefName);
}else {
infoTextView.setText("");
}
}
}
static final private int CHOOSE_THIEF = 0;
public void onClick(View view) {
Intent questionIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivityForResult(questionIntent,CHOOSE_THIEF);
}
}
Help me please :)
If you read other Stack Overflow questions, you will notice that well-written questions include the source code that is crashing (in your case, MainActivity) in addition to the stack trace.
In this case, I can tell just from the stack trace that you are calling findViewById() on your MainActivity too soon. This cannot be done until after your call to setContentView().
In particular, you appear to be calling findViewById() in the initializer of data member. Do not call inherited methods on Activity until after super.onCreate(), unless specifically directed otherwise.

Categories