I used the following code to add a view in a layout
LinearLayout linearLayout_row1_recent_released = (LinearLayout)findViewById(R.id.linearLayout);
View myview = findViewById(R.layout.row);
Button button = myview.findViewById(R.id.mybutton);
linearLayout_row1_recent_released.removeAllViews();
linearLayout_row1_recent_released.addView(myview,LinearLayout.LayoutParams.FILL_PARENT);
Using row.xml i've tried to get a view.
What i get is a FATAL EXCEPTION.
02-11 02:59:04.278: ERROR/AndroidRuntime(780): FATAL EXCEPTION: main
02-11 02:59:04.278: ERROR/AndroidRuntime(780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaa.ap/com.aaaaaa.ap.AppPlaceMain}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaa.ap/com.aaaaaa.ap.Store}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaa.ap/com.aaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1717)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:984)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.os.Looper.loop(Looper.java:126)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.main(ActivityThread.java:3900)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at java.lang.reflect.Method.invoke(Method.java:491)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at dalvik.system.NativeStart.main(Native Method)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaa.ap/com.aaaaaa.ap.Store}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaaa.ap/com.aaaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1543)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.widget.TabHost.setCurrentTab(TabHost.java:349)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 11 more
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aaaaaaa.ap/com.aaaaaa.ap.catalog.Home}: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1701)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1543)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.aaaaad.ap.Store.onCreate(Store.java:29)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 20 more
02-11 02:59:04.278: ERROR/AndroidRuntime(780): Caused by: java.lang.NullPointerException
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.view.ViewGroup.addView(ViewGroup.java:2684)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at com.aaaaa.ap.catalog.Home.onCreate(Home.java:51)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1665)
02-11 02:59:04.278: ERROR/AndroidRuntime(780): ... 26 more
Is there any other good way to add views dynamically to a linear layout? What have I done wrong here ?
I am guessing that the view R.layout.row is defined in a separate XML file, and you want to include it here. If that is the case,
findViewById(R.layout.row)
will not work because R.layout.row is not visible in the current activity.
You need to use layout inflater to inflate the view, and then you can add it to the linear layout. The way to do this is
LayoutInflaterinflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.row, null);
linearLayout_row1_recent_released.addView(myview,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) );
Your call to addView is wrong.
You are calling addView(View, int), but it should be: addView(View, LayoutParams):
linearLayout_row1_recent_released.addView(myview,
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT) );
Related
I've been having so much problem with this Live Wallpaper.
I have read alot online about these, and I thought I understood and got them.
When I tried to apply them to this live wallpaper, everything has been going very rough.
I've spent all day and night :-(
Could you someone please help me out?
My goal is to store the new password from edittextpreference to the
Sharedpreference, and then retrieve this password to compared with the login
password to if they are matched.
For example,
I have 2 edittextpreferences:
1) is for create new password which will be saved to the SharedPreference
2) is for login password.
The users will be granted the access when the login password is matched with the
one in the SharedPreference.
Please help me out,
I would be appreciated for your help.
prefs.java Code:
#SuppressWarnings("deprecation")
#Override
protected void onDestroy() {
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
{
}
}
{
SharedPreferences mlogin_password = this.getSharedPreferences("data_storage", MODE_PRIVATE);
Editor login_password = mlogin_password.edit();
login_password.putString("login", "login_pw2");
login_password.commit();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Context);
String s = sp.getString("login", null);
Sorry for 10000000 of error codes :-(
Logcat:
at android.util.Log.println_native(Native Method)
at android.util.Log.v(Log.java:117)
at rare_war.weapons.prefs.<init>(prefs.java:60)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at rare_war.weapons.prefs.<init>(prefs.java:65)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at rare_war.weapons.prefs.<init>(prefs.java:65)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:62)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:62)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:62)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:62)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:62)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:64)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:66)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:63)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:65)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:75)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:74)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:374)
at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:369)
at rare_war.weapons.prefs.<init>(prefs.java:75)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
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:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
at rare_war.weapons.prefs.<init>(prefs.java:68)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
... 11 more
My goal is to store the new password from edittextpreference to the
Sharedpreference...
Not a good idea. You shouldn't store passwords on SharedPreferences
I would suggest using a different approach like storing the encrypted password on a server and then check what the user entered against it.
Please, also make sure you read the Android guide on SharedPreferences
Hi you are saving password on sharedPreference named 'data_storage' and retrieving from default sharedPreference thats why you are not getting saved password.Try to save and retrieve preference value from same sharedPreference.
Why don't you use getSharedPreferences for the key "data_storage" and not for getDefaultSharedPreferences, in other words, Context? I'm not really sure about it, but you should try.
The mechanism works as follows: you save the key under a string name "date_storage" then you retrieve they key. In both cases you need to get the SharedPreferences with the line:
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Context);
After that use the "sp.get()" methods to get the required value for the saved string key ("data_storage").
In the course of my endevours I added two versions of androidplot to my project. I realised it is causing conflict so I tried removing both to start again and I am now getting
02-11 22:50:10.769: E/AndroidRuntime(20299): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cpdsessions.exercise_app/com.cpdsessions.exercise_app.ActivityLevelView}: android.view.InflateException: Binary XML file line #21: Error inflating class com.androidplot.xy.XYPlot
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.os.Looper.loop(Looper.java:150)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.main(ActivityThread.java:4385)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.reflect.Method.invoke(Method.java:507)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
02-11 22:50:10.769: E/AndroidRuntime(20299): at dalvik.system.NativeStart.main(Native Method)
02-11 22:50:10.769: E/AndroidRuntime(20299): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.androidplot.xy.XYPlot
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.Activity.setContentView(Activity.java:1742)
02-11 22:50:10.769: E/AndroidRuntime(20299): at com.cpdsessions.exercise_app.ActivityLevelView.onCreate(ActivityLevelView.java:28)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
02-11 22:50:10.769: E/AndroidRuntime(20299): ... 11 more
02-11 22:50:10.769: E/AndroidRuntime(20299): Caused by: java.lang.ClassNotFoundException: com.androidplot.xy.XYPlot in loader dalvik.system.PathClassLoader[/data/app/com.cpdsessions.exercise_app-1.apk]
02-11 22:50:10.769: E/AndroidRuntime(20299): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-11 22:50:10.769: E/AndroidRuntime(20299): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
02-11 22:50:10.769: E/AndroidRuntime(20299): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
02-11 22:50:10.769: E/AndroidRuntime(20299): ... 20 more
Can anyone tell me how to clean this up please?
I realised what the issue was here, I still had a androidplot element in my layout, so in fact the project wasn't fully cleaned of the attempt
Thanks
I have been trying to implement a sample application in order to study the working of Google maps API. I have been struck with the configuration itself. I can't seem to run the application.
Here's my code at Github :-
https://github.com/siva54/SampleMapApplication
And here's my logcat :-
02-11 15:09:07.492: I/Process(10080): Sending signal. PID: 10080 SIG: 9
02-11 15:09:17.012: E/dalvikvm(10364): Could not find class 'com.google.android.gms.maps.model.MarkerOptions', referenced from method com.myapp.gasapplication.MainActivity.setUpMap
02-11 15:09:17.012: W/dalvikvm(10364): VFY: unable to resolve new-instance 455 (Lcom/google/android/gms/maps/model/MarkerOptions;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:09:17.012: D/dalvikvm(10364): VFY: replacing opcode 0x22 at 0x0004
02-11 15:09:17.012: E/dalvikvm(10364): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.myapp.gasapplication.MainActivity.setUpMapIfNeeded
02-11 15:09:17.012: W/dalvikvm(10364): VFY: unable to resolve check-cast 452 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:09:17.012: D/dalvikvm(10364): VFY: replacing opcode 0x1f at 0x000e
02-11 15:09:17.012: D/dalvikvm(10364): DexOpt: unable to opt direct call 0x0cd0 at 0x06 in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:09:17.022: D/dalvikvm(10364): DexOpt: unable to opt direct call 0x0ccf at 0x0b in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:09:17.072: D/AndroidRuntime(10364): Shutting down VM
02-11 15:09:17.072: W/dalvikvm(10364): threadid=1: thread exiting with uncaught exception (group=0x40e02930)
02-11 15:09:17.082: E/AndroidRuntime(10364): FATAL EXCEPTION: main
02-11 15:09:17.082: E/AndroidRuntime(10364): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.gasapplication/com.myapp.gasapplication.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.os.Looper.loop(Looper.java:137)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.reflect.Method.invoke(Method.java:511)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-11 15:09:17.082: E/AndroidRuntime(10364): at dalvik.system.NativeStart.main(Native Method)
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Activity.setContentView(Activity.java:1881)
02-11 15:09:17.082: E/AndroidRuntime(10364): at com.myapp.gasapplication.MainActivity.onCreate(MainActivity.java:25)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Activity.performCreate(Activity.java:5104)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 11 more
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 21 more
02-11 15:09:17.082: E/AndroidRuntime(10364): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.myapp.gasapplication-1.apk
02-11 15:09:17.082: E/AndroidRuntime(10364): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-11 15:09:17.082: E/AndroidRuntime(10364): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-11 15:09:17.082: E/AndroidRuntime(10364): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
02-11 15:09:17.082: E/AndroidRuntime(10364): ... 24 more
02-11 15:10:58.032: E/dalvikvm(10887): Could not find class 'com.google.android.gms.maps.model.MarkerOptions', referenced from method com.myapp.gasapplication.MainActivity.setUpMap
02-11 15:10:58.032: W/dalvikvm(10887): VFY: unable to resolve new-instance 455 (Lcom/google/android/gms/maps/model/MarkerOptions;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:10:58.032: D/dalvikvm(10887): VFY: replacing opcode 0x22 at 0x0004
02-11 15:10:58.032: E/dalvikvm(10887): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.myapp.gasapplication.MainActivity.setUpMapIfNeeded
02-11 15:10:58.032: W/dalvikvm(10887): VFY: unable to resolve check-cast 452 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/myapp/gasapplication/MainActivity;
02-11 15:10:58.032: D/dalvikvm(10887): VFY: replacing opcode 0x1f at 0x000e
02-11 15:10:58.032: D/dalvikvm(10887): DexOpt: unable to opt direct call 0x0cd0 at 0x06 in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:10:58.032: D/dalvikvm(10887): DexOpt: unable to opt direct call 0x0ccf at 0x0b in Lcom/myapp/gasapplication/MainActivity;.setUpMap
02-11 15:10:58.092: D/AndroidRuntime(10887): Shutting down VM
02-11 15:10:58.092: W/dalvikvm(10887): threadid=1: thread exiting with uncaught exception (group=0x40e02930)
02-11 15:10:58.092: E/AndroidRuntime(10887): FATAL EXCEPTION: main
02-11 15:10:58.092: E/AndroidRuntime(10887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.gasapplication/com.myapp.gasapplication.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.os.Looper.loop(Looper.java:137)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.reflect.Method.invoke(Method.java:511)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-11 15:10:58.092: E/AndroidRuntime(10887): at dalvik.system.NativeStart.main(Native Method)
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Activity.setContentView(Activity.java:1881)
02-11 15:10:58.092: E/AndroidRuntime(10887): at com.myapp.gasapplication.MainActivity.onCreate(MainActivity.java:25)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Activity.performCreate(Activity.java:5104)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 11 more
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 21 more
02-11 15:10:58.092: E/AndroidRuntime(10887): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: /data/app/com.myapp.gasapplication-2.apk
02-11 15:10:58.092: E/AndroidRuntime(10887): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-11 15:10:58.092: E/AndroidRuntime(10887): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-11 15:10:58.092: E/AndroidRuntime(10887): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
02-11 15:10:58.092: E/AndroidRuntime(10887): ... 24 more
Would you please help? Thanks in advance.
It looks like it's not finding the Google Maps classes at runtime. Are you running this on a device or an emulator because you can't use Google Maps v2 on an emulator at this time.
If you are running on a device then make sure you have Google Play Services installed. It contains the runtime for Google Maps v2.
Solved my Problem. The issue occurred because even though I i referenced the google play library, The reference is not considered by eclipse and it was shown by a cross mark. I have resolved that with the help of the following stackoverflow post:-
In eclipse, unable to reference an android library project in another android project
I have two inner fragments in a activity.
Activity is called: MainFragmentActivity (extends FragmentACtivity)
Inside is this:
public static class FeaturedFrag extends ListFragment {
public static class TopFrag extends ListFragment {
How would I identify here?
<fragment
android:id="#+id/featured_frag"
android:layout_width="400dp"
android:layout_height="match_parent"
class="com.---.---.MainFragmentActvity$FeaturedFrag" />
<fragment
android:id="#+id/top_items_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.---.---.MainFragmentActvity$TopItemFrag" />
Changed the XML to the recommendation, LogCat below.
12-05 00:27:35.639: E/AndroidRuntime(1243): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MainFragmentActvit$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
I do have a class with that name, an empty constructor and it is public.
Full LogCat:
12-05 00:37:38.090: E/AndroidRuntime(1384): FATAL EXCEPTION: main
12-05 00:37:38.090: E/AndroidRuntime(1384): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.---.---/com.---.---.master.MainFragmentActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.os.Looper.loop(Looper.java:137)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.reflect.Method.invoke(Method.java:511)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-05 00:37:38.090: E/AndroidRuntime(1384): at dalvik.system.NativeStart.main(Native Method)
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Activity.setContentView(Activity.java:1867)
12-05 00:37:38.090: E/AndroidRuntime(1384): at com.---.---.master.MainFragmentActivity.onCreate(MainFragmentActivity.java:85)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Activity.performCreate(Activity.java:5008)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 11 more
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.---.---.MainFragmentActivity$MasterFrag: make sure class name exists, is public, and has an empty constructor that is public
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:395)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:363)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 21 more
12-05 00:37:38.090: E/AndroidRuntime(1384): Caused by: java.lang.ClassNotFoundException: com.kickinglettce.rate_this.MainFragmentActivity$MasterFrag
12-05 00:37:38.090: E/AndroidRuntime(1384): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-05 00:37:38.090: E/AndroidRuntime(1384): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-05 00:37:38.090: E/AndroidRuntime(1384): at android.support.v4.app.Fragment.instantiate(Fragment.java:385)
12-05 00:37:38.090: E/AndroidRuntime(1384): ... 24 more
Sample code from one of the inner fragments:
public static class MasterFrag extends ListFragment {
// fields
public MasterFrag() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.mastercat, container, false);
}
Proofread all your code. Make sure all class names are the same, are in the same packages, etc. Otherwise Android does not know where anything is.
As for your your original question, the format is class = "package.Activity$Fragment"
What I have to do for this memory problem ?
02-11 15:40:30.959: E/AndroidRuntime(5108): FATAL EXCEPTION: main
02-11 15:40:30.959: E/AndroidRuntime(5108): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firewards/com.firewards.Menu}: android.view.InflateException: Binary XML file line #122: Error inflating class <unknown>
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.os.Looper.loop(Looper.java:123)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.main(ActivityThread.java:3729)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Method.invoke(Method.java:507)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
02-11 15:40:30.959: E/AndroidRuntime(5108): at dalvik.system.NativeStart.main(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: android.view.InflateException: Binary XML file line #122: Error inflating class <unknown>
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.Activity.setContentView(Activity.java:1657)
02-11 15:40:30.959: E/AndroidRuntime(5108): at com.firewards.Menu.onCreate(Menu.java:66)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 11 more
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: java.lang.reflect.InvocationTargetException
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Constructor.constructNative(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 27 more
02-11 15:40:30.959: E/AndroidRuntime(5108): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.view.View.<init>(View.java:1951)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageView.<init>(ImageView.java:112)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageButton.<init>(ImageButton.java:85)
02-11 15:40:30.959: E/AndroidRuntime(5108): at android.widget.ImageButton.<init>(ImageButton.java:81)
02-11 15:40:30.959: E/AndroidRuntime(5108): ... 30 more
Yeah it feels like a memory issues, try releasing some bitmaps prior to accessing that
particular View.
I suggest to check out this video http://dubroy.com/blog/google-io-memory-management-for-android-apps/ which talks about Android memory management.
One thing worth mentioning is that prior to honeycomb, bitmaps were allocated in the native
heap, so watch out for it when profiling memory.
If you're on a device which if Honeycomb or newer, the bitmaps are allocated in the managed
heap.