android lockscreen settext application crash - android

i have used a code similar to one of stackoverflow links:
how to change system alarm setting text dynamic
to only settext on the lock screen but my application crashes when i run it, any idea what i'm missing?
my mainactivty:
package l.a;
import java.net.ContentHandler;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
public class LockscreenActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context= getApplicationContext();
KeyguardManager _guard = (KeyguardManager)
context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock _keyguardLock = _guard.newKeyguardLock("KeyguardLockWrapper");
//to disable
_keyguardLock.disableKeyguard();
String message ="New alarm :";
Settings.System.putString(this.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED, message);
//to enable
_keyguardLock.reenableKeyguard();
}
}
my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="l.a"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".LockscreenActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the logcat:
04-03 16:43:53.920: D/AndroidRuntime(486): Shutting down VM
04-03 16:43:53.928: W/dalvikvm(486): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
04-03 16:43:53.968: E/AndroidRuntime(486): Uncaught handler: thread main exiting due to uncaught exception
04-03 16:43:54.138: E/AndroidRuntime(486): java.lang.RuntimeException: Unable to start activity ComponentInfo{l.a/l.a.LockscreenActivity}: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=486, uid=10040 requires android.permission.WRITE_SETTINGS
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Looper.loop(Looper.java:123)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-03 16:43:54.138: E/AndroidRuntime(486): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 16:43:54.138: E/AndroidRuntime(486): at java.lang.reflect.Method.invoke(Method.java:521)
04-03 16:43:54.138: E/AndroidRuntime(486): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-03 16:43:54.138: E/AndroidRuntime(486): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-03 16:43:54.138: E/AndroidRuntime(486): at dalvik.system.NativeStart.main(Native Method)
04-03 16:43:54.138: E/AndroidRuntime(486): Caused by: java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.SettingsProvider uri content://settings/system from pid=486, uid=10040 requires android.permission.WRITE_SETTINGS
04-03 16:43:54.138: E/AndroidRuntime(486): at android.os.Parcel.readException(Parcel.java:1218)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.content.ContentProviderProxy.insert(ContentProviderNative.java:445)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.content.ContentResolver.insert(ContentResolver.java:629)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.provider.Settings$NameValueTable.putString(Settings.java:464)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.provider.Settings$System.putString(Settings.java:591)
04-03 16:43:54.138: E/AndroidRuntime(486): at l.a.LockscreenActivity.onCreate(LockscreenActivity.java:43)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-03 16:43:54.138: E/AndroidRuntime(486): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-03 16:43:54.138: E/AndroidRuntime(486): ... 11 more

well by simply reading the logcat i found this: requires android.permission.WRITE_SETTINGS at the end of the 4th line.

Related

add google maps in an android application

I'm new in Android development. I want to add Google maps to my application. I have done lots of searches but still the same problem arises when I run the application "Unfortunately , application has stopped"
So this is my java class
package com.example.hellomap;
import com.google.android.maps.MapView;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_main);
MapView map =(MapView) findViewById(R.id.map);
}
}
the xml file :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
and the Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellomap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name="com.example.hellomap.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKSp9pb7g8Wkga2SgeoT_MSe0JG59DkSU" />
</application>
</manifest>
The LogCat shows:
04-03 13:45:42.574: E/AndroidRuntime(1164): FATAL EXCEPTION: main
04-03 13:45:42.574: E/AndroidRuntime(1164): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellomap/com.example.hellomap.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.os.Looper.loop(Looper.java:137)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.reflect.Method.invoke(Method.java:511)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-03 13:45:42.574: E/AndroidRuntime(1164): at dalvik.system.NativeStart.main(Native Method)
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.setContentView(Activity.java:1867)
04-03 13:45:42.574: E/AndroidRuntime(1164): at com.example.hellomap.MainActivity.onCreate(MainActivity.java:23)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.performCreate(Activity.java:5008)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 11 more
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:584)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:552)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Activity.onCreateView(Activity.java:4656)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 20 more
04-03 13:45:42.574: E/AndroidRuntime(1164): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
04-03 13:45:42.574: E/AndroidRuntime(1164): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-03 13:45:42.574: E/AndroidRuntime(1164): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-03 13:45:42.574: E/AndroidRuntime(1164): at android.app.Fragment.instantiate(Fragment.java:574)
04-03 13:45:42.574: E/AndroidRuntime(1164): ... 23 more
04-03 13:50:42.626: I/Process(1164): Sending signal. PID: 1164 SIG: 9
Thanks for help :)
EXCEPTION :- ClassNotFoundException
please check GooglePlayService Library Project First.
Second Thing You Can Not Type Cast Fragment To Map View, please read this
Update:-
Follow The Step:-
1)Create New Project
2)Import GooglePlayService Library project into Your Workspace.
3)assign Google play Service library project as library project to your project
4)now add Map Fragment/Supported Map Fragment into your activity layout file
5)make sure this class found
how to check==>press control Key from keyboard and click on class name id you found class then it's okay other wise fix it first.
i prefer to use Supported Fragment.
6)define all permission as describe in link i posted previously.
6)now its time to generate api key for map ,follow the step from given link.
Thanks i hope its help

Starting with Android Google Maps API V2

I am newbie on Android Google Maps API and I was trying to develop a small app using the API. I use as a reference the Google documentation form: https://developers.google.com/maps/documentation/android/ and I follow all the step with caution. When I build it and install it on to my device (Android 2.3.6) the app crash. I follow all the instructions to sign the app and get the API key for this specific app, tried all the step of the documentation several times without any good results. Please, can someone help me with this? I there something missing?
Thank you!
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.uprm_map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<permission
android:name="com.application.uprm_map.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.application.uprm_map.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.application.uprm_map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<my own key>"/>
</application>
</manifest>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
MainActivity.java
package com.application.uprm_map;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Exeptions:
03-05 02:29:27.645: D/dalvikvm(32056): GC_EXTERNAL_ALLOC freed 42K, 49% free 2748K/5379K, external 0K/0K, paused 21ms
03-05 02:29:27.650: D/AndroidRuntime(32056): Shutting down VM
03-05 02:29:27.650: W/dalvikvm(32056): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
03-05 02:29:27.655: E/AndroidRuntime(32056): FATAL EXCEPTION: main
03-05 02:29:27.655: E/AndroidRuntime(32056): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.uprm_map/com.application.uprm_map.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.os.Looper.loop(Looper.java:130)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.reflect.Method.invoke(Method.java:507)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.NativeStart.main(Native Method)
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:234)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Activity.setContentView(Activity.java:1679)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.application.uprm_map.MainActivity.onCreate(MainActivity.java:11)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 11 more
03-05 02:29:27.655: E/AndroidRuntime(32056): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.application.uprm_map-1.apk]
03-05 02:29:27.655: E/AndroidRuntime(32056): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-05 02:29:27.655: E/AndroidRuntime(32056): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
03-05 02:29:27.655: E/AndroidRuntime(32056): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-05 02:29:27.655: E/AndroidRuntime(32056): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-05 02:29:27.655: E/AndroidRuntime(32056): ... 19 more
03-05 02:29:29.660: I/dalvikvm(32056): threadid=4: reacting to signal 3
03-05 02:29:29.665: I/dalvikvm(32056): Wrote stack traces to '/data/anr/traces.txt'
First thing as you are having the API level 8 or below so you have to use the SupportMapFragment instead of MapFragment as below in your layout file.
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Second thing you have to extend the FragmentActivity instead of Activity :
public class MainActivity extends FragmentActivity {
Do the above changes and then run your application.

Live Wall paper force closes

My Live wall app force closes when clicked on the Settings button.
wall_setting.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="time_interval"
android:title="#string/app_name"
android:summary="something"
android:defaultValue="3000"
android:entries="#array/updateInterval"
android:entryValues="#array/updateIntervalValues"
/>
</PreferenceScreen>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="#drawable/ic_launcher"
android:settingsActivity="com.zacharia.lunar.WallService"
android:description="#string/wall_desc" />
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zacharia.lunar"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true"></uses-feature>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<service
android:name="com.zacharia.lunar.WallService"
android:enabled="true"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService"></action>
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/main"></meta-data>
</service>
<activity
android:name="com.zacharia.lunar.SettingActivity"
android:label="#string/title_activity_main"
android:theme="#android:style/Theme.Light.WallpaperSettings"
android:exported="true">
</activity>
</application>
</manifest>
Errors
09-14 20:36:53.491: E/AndroidRuntime(542): java.lang.IllegalStateException: Could not execute method of the activity
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.View$1.onClick(View.java:2031)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.View.performClick(View.java:2364)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.View.onTouchEvent(View.java:4179)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.widget.TextView.onTouchEvent(TextView.java:6541)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.View.dispatchTouchEvent(View.java:3709)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.wallpaper.livepicker.LiveWallpaperPreview.dispatchTouchEvent(LiveWallpaperPreview.java:199)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.os.Handler.dispatchMessage(Handler.java:99)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.os.Looper.loop(Looper.java:123)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-14 20:36:53.491: E/AndroidRuntime(542): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 20:36:53.491: E/AndroidRuntime(542): at java.lang.reflect.Method.invoke(Method.java:521)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-14 20:36:53.491: E/AndroidRuntime(542): at dalvik.system.NativeStart.main(Native Method)
09-14 20:36:53.491: E/AndroidRuntime(542): Caused by: java.lang.reflect.InvocationTargetException
09-14 20:36:53.491: E/AndroidRuntime(542): at com.android.wallpaper.livepicker.LiveWallpaperPreview.configureLiveWallpaper(LiveWallpaperPreview.java:113)
09-14 20:36:53.491: E/AndroidRuntime(542): at java.lang.reflect.Method.invokeNative(Native Method)
09-14 20:36:53.491: E/AndroidRuntime(542): at java.lang.reflect.Method.invoke(Method.java:521)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.view.View$1.onClick(View.java:2026)
09-14 20:36:53.491: E/AndroidRuntime(542): ... 20 more
09-14 20:36:53.491: E/AndroidRuntime(542): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.zacharia.lunar/com.zacharia.lunar.WallService}; have you declared this activity in your AndroidManifest.xml?
09-14 20:36:53.491: E/AndroidRuntime(542): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.app.Activity.startActivityForResult(Activity.java:2749)
09-14 20:36:53.491: E/AndroidRuntime(542): at android.app.Activity.startActivity(Activity.java:2855)
09-14 20:36:53.491: E/AndroidRuntime(542): ... 24 more
In main.xml
android:settingsActivity="com.zacharia.lunar.WallService"
should read;
android:settingsActivity="com.zacharia.lunar.SettingActivity"

Starting FragmentActivity from Activity with Intent

I'm getting a force close every time I try to start a FragmentActivity from an Activity using an Intent. Here's the code from the Activity:
Intent intent = new Intent(getApplicationContext(), OrgHome.class);
intent.putExtra("Username", organization_name.getText().toString());
startActivity(intent);
And here's the logcat:
08-01 16:52:45.823: E/AndroidRuntime(600): FATAL EXCEPTION: main
08-01 16:52:45.823: E/AndroidRuntime(600): java.lang.NoClassDefFoundError: com.project3.organizations.OrgHome
08-01 16:52:45.823: E/AndroidRuntime(600): at com.project3.organizations.MainActivity$1$1.mobDBResponse(MainActivity.java:76)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:78)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:1)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 16:52:45.823: E/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)
08-01 16:52:48.053: I/Process(600): Sending signal. PID: 600 SIG: 9
OrgHome.class is defined in the manifest correctly. What's going on here?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project3.organizations"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="OrgHome"></activity>
</application>
</manifest>
Change the manifest:
Use this if OrgHome is in the same place as MainActivity
<activity android:name=".OrgHome" />
Use this if it's in a sub-folder
<activity android:name=".sub.path.to.OrgHome" />
Or specify the whole path
<activity android:name="entire.path.to.OrgHome" />
for addressing the Fragment activities you should write (getactivity(),nameofOtherActivity.class); and you should be all right.

Unable to load webpage using WebView in Android

I have recently taken up Android Development and I was looking to using the WebView display webpages. I picked up from the sample that was given on Google site and for some reason the emulator kept saying page was not available. I searched in StackOverflow and found links relating to WebViewClient. I tried that also but no luck there, I have checked multiple times about the manifest entry for internet permission and its there. As a test I ran the browser available within the emulator and sure enough my firewall popped up a question on whether to allow it access or not. The pop up never came to me when I was running it from program. The code that I have is what is there Google pages
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
I tried loading simple html directly using loadData and it worked fine. I am at loss as to what is happening and how this can be resolved. I would appreciate any help on this.
Adding the Android Manifest here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
To check if its just a WebView thingy, I tried accessing the internet using httpGet and httpResonse classes and got the same problem, the code was not able to connect to the given site. It failed stating the below
05-10 00:37:53.191: WARN/System.err(294): java.net.UnknownHostException: feeds.feedburner.com
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByName(InetAddress.java:242)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-10 00:37:53.280: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-10 00:37:53.291: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-10 00:37:53.301: WARN/System.err(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:43)
05-10 00:37:53.301: WARN/System.err(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:37:53.309: WARN/System.err(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:37:53.322: WARN/System.err(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:37:53.330: WARN/System.err(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:37:53.340: WARN/System.err(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:37:53.361: WARN/System.err(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:37:53.361: WARN/System.err(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:37:53.372: WARN/System.err(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:37:53.401: WARN/System.err(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:37:56.773: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
05-10 00:37:58.083: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44fc9108 com.example.hellowebview/.HelloWebView}
05-10 00:38:06.300: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000)
05-10 00:38:06.651: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3724c8:0x3725d4] in 7266287 ns
05-10 00:38:06.720: INFO/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x371380:0x371548] in 1486222 ns
05-10 00:38:30.430: DEBUG/AndroidRuntime(294): Shutting down VM
05-10 00:38:30.430: WARN/dalvikvm(294): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): FATAL EXCEPTION: main
05-10 00:38:30.752: ERROR/AndroidRuntime(294): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellowebview/com.example.hellowebview.HelloWebView}: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): Caused by: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:51)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): ... 11 more
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am not sure what is the significance of this but would appreciate if anyone could elaborate.
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
mWebView = (WebView) findViewById(R.id.webview);
WebSettings setting =mWebView.getSettings();
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
mWebView.loadUrl("http://www.google.com");
Use this code .shouldOverrideUrlLoading() not use compulsary.use this code and please reply me this code work or not
Your code looks fine. I would make sure internet is working correctly on the emulator by browsing a few pages on the Android Browser. I have had problems before where the emulator would lose network access.

Categories

Resources