I am creating android application which is open a webpage using webview but on run time I got an error . This is mobile js page in which is I want to open webview.
Log-cat :
06-19 00:44:25.756: I/Process(1130): Sending signal. PID: 1130 SIG: 9
06-19 00:46:45.136: D/AndroidRuntime(1156): Shutting down VM
06-19 00:46:45.136: W/dalvikvm(1156): threadid=1: thread exiting with uncaught exception (group=0xb4a48ba8)
06-19 00:46:45.156: E/AndroidRuntime(1156): FATAL EXCEPTION: main
06-19 00:46:45.156: E/AndroidRuntime(1156): Process: com.example.dynakodetechnologypvt.ltd, PID: 1156
06-19 00:46:45.156: E/AndroidRuntime(1156): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dynakodetechnologypvt.ltd/com.example.dynakodetechnologypvt.ltd.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.os.Handler.dispatchMessage(Handler.java:102)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.os.Looper.loop(Looper.java:136)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-19 00:46:45.156: E/AndroidRuntime(1156): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 00:46:45.156: E/AndroidRuntime(1156): at java.lang.reflect.Method.invoke(Method.java:515)
06-19 00:46:45.156: E/AndroidRuntime(1156): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-19 00:46:45.156: E/AndroidRuntime(1156): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-19 00:46:45.156: E/AndroidRuntime(1156): at dalvik.system.NativeStart.main(Native Method)
06-19 00:46:45.156: E/AndroidRuntime(1156): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-19 00:46:45.156: E/AndroidRuntime(1156): at com.example.dynakodetechnologypvt.ltd.MainActivity.onCreate(MainActivity.java:19)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.Activity.performCreate(Activity.java:5231)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-19 00:46:45.156: E/AndroidRuntime(1156): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-19 00:46:45.156: E/AndroidRuntime(1156): ... 11 more
Main Activity
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
String url = "http://www.google.com";
WebView view = (WebView) this.findViewById(R.id.webView1);
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(url);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Android manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dynakodetechnologypvt.ltd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name="com.example.dynakodetechnologypvt.ltd.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>
</application>
</manifest>
How can I solve this please help
ActionBarActivity requires a theme that extends from Theme.AppCompat, otherwise your app will crash with this error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
So in Manifest file use the new theme with MainActivity: as
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dynakodetechnologypvt.ltd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name="com.example.dynakodetechnologypvt.ltd.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.AppCompat"> //Add here
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This will add Actionbar in MainActivity
But usually you need to customize you Actionbar. To do this you need to create two styles with Theme.AppCompat parent, for example, "#style/Theme.AppCompat.Light". First one will be for api 11>= (versions of android with build in android actionbar), second one for api 7-10 (no build in actionbar).
Let's look at first style. It will be located in res/values-v11/styles.xml . It will look like this:
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 11+ -->
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 11+ -->
<item name="android:background">#drawable/ab_custom_solid_styled</item>
<item name="android:backgroundStacked"
>#drawable/ab_custom_stacked_solid_styled</item>
<item name="android:backgroundSplit"
>#drawable/ab_custom_bottom_solid_styled</item>
</style>
And you need to have same style for api 7-10. It will be located in res/values/styles.xml, BUT because that api levels don't yet know about original android actionbar style items, we should use one, provided by support library. ActionBar Compat items are defined just like original android, but without "android:" part in the front:
<style name="Theme.Styled" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the default namespace affects API levels 7-11 -->
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the default namespace affects API levels 7-11 -->
<item name="background">#drawable/ab_custom_solid_styled</item>
<item name="backgroundStacked">#drawable/ab_custom_stacked_solid_styled</item>
<item name="backgroundSplit">#drawable/ab_custom_bottom_solid_styled</item>
</style>
For more info see ActionBarCompat and I/O 2013 App Source
Related
This question already has answers here:
Error Inflating class fragment in activity maps xml
(3 answers)
Closed 6 years ago.
I just wanted to run a simple map fragment but I keep getting InflateException. I also asked a similar question but I made a new Google Maps project for simplicity.
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Process: com.example.ali.myapplication, PID: 1785
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ali.myapplication/com.example.ali.myapplication.MapsActivity}: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-01 14:14:20.109 1785-1785/com.example.ali.myapplication E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
MapsActivity.java:
package com.example.ali.myapplication;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
activity_maps.xml:
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#619ec9"
xmlns:android="http://schemas.android.com/apk/res/android">
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map" tools:context=".MapsActivity"
class="com.google.android.gms.maps.SupportMapFragment"
tools:layout="#layout/activity_maps"
android:layout_width="362dp"
android:layout_height="323dp"
/>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.myapplication" >
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Fragment should be added to a frame layour, it cant be directly used.
Update your code and let me know if works
Greetings my developer friends!
I created a demo app to test the material design for minSdk 14 and targetSdj 23. I have the following files below. It works fine below the 21 API. I believe the culprit is Styles-v21.xml as the app worked fine before that.
Its a simple setup, just one activity. I am testing the Material theme and AppCompat theme for working with the following scenario.
Theme.AppCompat for API below 21.
Theme.Material for API 21 and 21+.
The app works fine below API 21, but above 21+ the App crashes saying,"Unfortunately materialTest has stopped."
The error is as follows:
FATAL EXCEPTION: main
Process: net.slidenerd.materialtest, PID: 28204
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.slidenerd.materialtest/net.slidenerd.materialtest.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at net.slidenerd.materialtest.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
MainActivity.java
package net.slidenerd.materialtest;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Styles-v21.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
</style>
</resources>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.slidenerd.materialtest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Solution: I solved this issue by extending Activity instead of AppCompatActivity and the application runs fine on both API 14+ to API 23 smoothly. But, could you justify the preferred solution to this problem.
All the code needed to produce the error is above.
Note: To produce the error, MainActivity should extend AppCompatActivity and you should run on API 21 or above.
Could anyone explain the ideal case happening here so as to understand the underlying problem?
Thank You!
If your activity extends from AppCompatActivity is mandatory that your activity theme must be Theme.AppCompat theme (or descendant).
If you want to use other theme don't extends from AppCompatActivity and you'll stop receiving java.lang.IllegalStateException.
Hope this helps!!
The AppCompatActivity is supposed to be used with other components from the Compat library, and they expect that you have defined some attributes in your theme (like android:colorPrimary, android:colorSecondary, etc). If these attributes are not defined in your theme, the components that need them will throw a RuntimeException. Theme.AppCompat themes define these attributes.
In the reverse way there is no problem. You can extend from Activity and use a theme from Theme.AppCompat without problems, but you will lose some functionality provided by the AppCompatActivity.
So, if you want to use AppCompatActivity, use a Theme.AppCompat theme or define the attributes it requires in your theme. You can go to the line that throws the exception to see which attribute is needed.
I'm trying to make a Live wallpaper app in android with the libgdx library, but i have a problem. whenever the settings button is pressed in live wallpaper picker the app crashes and shows the message: "Unfortunately, Live Wallpaper Picker has stopped", otherwise everything works.
I've been following this example:
How to create android live wallpaper
and i tried looking for a solution here, this page for example:
Live Wallpaper crash when tap on Settings
but nothing fixes my problem - I think its in the xml files somewhere, But maybe there's an issue combining libgdx with livewallpaper?
I've been trying to find a solution to this but can't, would really appreciate some help.
here is my code:
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mygdx.game.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
<uses-feature android:required="true" android:name="android.software.live_wallpaper"> </uses-feature>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name="com.mygdx.game.android.AndroidLauncher"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.mygdx.game.android.LivewallpaperSettings"
android:label="Livewallpaper Settings"
android:theme="#android:style/Theme.Light.WallpaperSettings"
android:exported="true">
</activity>
<service
android:name="com.mygdx.game.android.LiveWallpaper"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/wallpaper" />
</service>
</application>
</manifest>
LivewallpaperSettings.java
package com.mygdx.game.android;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class LivewallpaperSettings extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
getPreferenceManager().setSharedPreferencesName(LiveWallpaper.SHARED_PREFS_NAME);
addPreferencesFromResource(R.xml.settings);
getPreferenceManager().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
#Override
protected void onResume()
{
super.onResume();
}
#Override
protected void onDestroy()
{
getPreferenceManager().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key)
{
}
}
wallpaper.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="lwp.example.android.LivewallpaperSettings"/>
settings.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="settings"
android:key="settings">
<ListPreference
android:key="livewallpaper_testpattern"
android:title="title 1"
android:summary="do 1"
android:entries="#array/livewallpaper_testpattern_names"
android:entryValues="#array/livewallpaper_testpattern_prefix"/>
<CheckBoxPreference android:key="livewallpaper_movement"
android:title="title 2"
android:summary="do 2"
android:summaryOn="Moving test pattern"
android:summaryOff="Still test pattern"/>
</PreferenceScreen>
Here is my logcat when I get the error:
11-14 15:40:04.254: W/GL2JNIView(1654): creating OpenGL ES 2.0 context
11-14 15:40:04.265: I/AndroidGraphics(1654): OGL renderer: Adreno (TM) 320
11-14 15:40:04.265: I/AndroidGraphics(1654): OGL vendor: Qualcomm
11-14 15:40:04.265: I/AndroidGraphics(1654): OGL version: OpenGL ES 3.0 V#84.0 AU#05.00.02.006.020 (CL#)
11-14 15:40:04.265: I/AndroidGraphics(1654): OGL extensions: GL_AMD_compressed_ATC_texture GL_AMD_performance_monitor GL_AMD_program_binary_Z400 GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_robustness GL_EXT_texture_format_BGRA8888 GL_EXT_texture_type_2_10_10_10_REV GL_NV_fence GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_depth24 GL_OES_EGL_image GL_OES_EGL_sync GL_OES_EGL_image_external GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_get_program_binary GL_OES_packed_depth_stencil GL_OES_depth_texture_cube_map GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_3D GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_vertex_type_10_10_10_2 GL_OES_vertex_array_object GL_QCOM_alpha_test GL_QCOM_binning_control GL_QCOM_driver_control GL_QCOM_perfmon_global_mode GL_QCOM_extended_get GL_QCOM_extended_get2 GL_QCOM_tiled_rendering GL_QCOM_writeonly_rendering GL_EXT_sRGB GL_EXT_sRGB_write_control GL_EXT_texture_sRGB_decode GL_EXT_multisampled_render_to_texture GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_disjoint_timer_query
11-14 15:40:04.265: W/Adreno-EGL(1654): <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
11-14 15:40:04.265: W/Adreno-EGL(1654): <qeglDrvAPI_eglGetConfigAttrib:632>: EGL_BAD_ATTRIBUTE
11-14 15:40:04.265: I/AndroidGraphics(1654): framebuffer: (5, 6, 5, 0)
11-14 15:40:04.265: I/AndroidGraphics(1654): depthbuffer: (16)
11-14 15:40:04.265: I/AndroidGraphics(1654): stencilbuffer: (0)
11-14 15:40:04.265: I/AndroidGraphics(1654): samples: (0)
11-14 15:40:04.265: I/AndroidGraphics(1654): coverage sampling: (false)
11-14 15:40:04.333: I/Running LiquidFun version(1654): LiquidFun 1.1.0
11-14 15:40:04.333: I/720.0(1654): 1280.0
11-14 15:40:04.429: I/AndroidInput(1654): sensor listener setup
11-14 15:40:09.043: I/WallpaperService(1654): service destroyed
11-14 15:40:09.043: I/WallpaperService(1654): engine paused
11-14 15:40:09.217: E/Surface(1654): queueBuffer: error queuing buffer to SurfaceTexture, -19
11-14 15:40:09.218: W/Adreno-EGLSUB(1654): <SwapBuffers:1344>: failed to queueBuffer
11-14 15:40:09.218: W/Adreno-EGL(1654): <qeglDrvAPI_eglSwapBuffers:3798>: EGL_BAD_SURFACE
11-14 15:40:09.220: I/AndroidInput(1654): sensor listener tear down
11-14 15:40:09.236: E/Surface(1654): queueBuffer: error queuing buffer to SurfaceTexture, -19
11-14 15:40:09.236: W/Adreno-EGLSUB(1654): <SwapBuffers:1344>: failed to queueBuffer
11-14 15:40:09.236: W/Adreno-EGL(1654): <qeglDrvAPI_eglSwapBuffers:3798>: EGL_BAD_SURFACE
11-14 15:40:09.244: I/WallpaperService(1654): engine surface destroyed
I found the problem, I gave a wrong reference to the "LivewallpaperSettings.java"
class in the "wallpaper.xml" file:
instead:
android:settingsActivity="lwp.example.android.LivewallpaperSettings
it should be:
android:settingsActivity="com.mygdx.game.android.LivewallpaperSettings"
i used a different project as reference and copied it without changing it to the correct path. sorry.. wasted my time and of others :/
thanks for trying to help.
I am a beginning in trying to create applications for android using Eclipse (also why i didn't do pictures). I started to learn to program by following Site (link). I tried this 3 times and each times it creates 2 projects. First one always called 'appcompat_v7' and the second one what ever i called it. In this instance I called it 'FirstApp'. In the project FirstApp, I could not find /res/layout containing anything so i created it, calling it fragment_main.xml. Containing:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
</LinearLayout>
I edited my 'androidmanifest.xml' to say:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And my strings.xml says:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">FirstApp</string>
<string name="edit_message">Enter a message</string>
</resources>
When running on my Samsung Galaxy S4 or on a AVD manager:
(settings are platform: 4.4W , API Lvl: 20 , and CPU/ABI: Android Wear
ARM (armeabi-v7a) , Device: Nexus 5)
Both give me the same error. "Unfortunately, (app name) has stopped."
And my LogCat gives me this log:
~Not late-enabling CheckJNI (already on)
~Shutting down VM
~threadid=1: thread exiting with uncaught exception (group=0xb2aa9d70)
~FATAL EXCEPTION: main
~Process: com.example.firstapp, PID: 745
~java.lang.RuntimeException: Unable to instantiate activity ComponentI
nfo{com.example.firstapp/com.example.firstapp.MainActivity}: java.lan
g.ClassNotFoundException: Didn't find class "com.example.firstapp.Mai
nActivity" on path: DexPathList[[zip file "/data/app/com.example.firs
tapp-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.firs
tapp-2, /system/lib]]
~at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2123)
~at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
~at android.app.ActivityThread.access$800(ActivityThread.java:138)
~at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
~at android.os.Handler.dispatchMessage(Handler.java:102)
~at android.os.Looper.loop(Looper.java:136)
~at android.app.ActivityThread.main(ActivityThread.java:5026)
~at java.lang.reflect.Method.invokeNative(Native Method)
~at java.lang.reflect.Method.invoke(Method.java:515)
~at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
~at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
~at dalvik.system.NativeStart.main(Native Method)
~Caused by: java.lang.ClassNotFoundException: Didn't find class "com.e
xample.firstapp.MainActivity" on path: DexPathList[[zip file "/data/a
pp/com.example.firstapp-2.apk"],nativeLibraryDirectories=[/data/app-l
ib/com.example.firstapp-2, /system/lib]]
~at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
~at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
~at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
~at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
~at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
~ ... 11 more
~Sending signal. PID: 745 SIG: 9
I have not edited anything else, but those xml files (strings.xml, fragment_main.xml, and AndroidManifest.xml)
Here is a pic of my packages:
Please help to remove this error. Thanks!
First of all, the reason that your app is creating two projects is for compatibility with devices running below API 14. I would recommend (and this is just a personal preference) that, as a beginner, when you create your projects you should set the minimum API level to 14.
When setting up a new project, check the check box that says 'Create activity', right under 'Create custom launcher icon':
Among the automatically created files, you should find a MainActivity.java file (in src > com.example.YourAppName) and an activity_main.xml layout file (in res > layout). If they are not created, this points to issues with your Eclipse/ADT/SDK setup.
So my advice would be to create a new project (above API 14) and run it without editing/creating any files. If it works, then you're good to go.
I have the launch activity called MainActivity that will eventually start another called SearchResultsActivity.
They both extend ActionBarActivity, and the second is yet to be written, for now it is just a stub with:
#Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.search_results);
}
The layout XML is as follows, just a ListView in a white background:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/list_products"
android:layout_gravity="center_horizontal" />
</LinearLayout>
The app is crashing on setContentView() with the following logcat:
17348-17348/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.SearchResultsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1682)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:940)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
at com.example.myapp.SearchResultsActivity.onCreate(SearchResultsActivity.java:42) <-- this is setContentView()
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1630)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1682)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:940)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3714)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)
Here's the manifest excerpt:
<activity
android:name="com.example.myapp.MainActivity"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Styled">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myapp.SearchResultsActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Styled"
android:configChanges="orientation|keyboardHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myapp.MainActivity" />
</activity>
I thought it could be some issue with the layout, but then I decide to replace R.layout.search_results with R.layout.home, which is the same XML used in MainActivity, therefore should work. But it crashes in the very same line.
Any ideas on what could be causing this?
As others have pointed out, your error is likely in your onCreate code for your second activity. If you read the documentation here you'll see they start their activity off with onCreate and an immediate call back to super.onCreate(...)
Your code should be as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //added this line
setContentView(R.layout.search_results);
}
If you chose to have your IDE automatically generate an Activity stub, it will always place the call to super.onCreate in your activity. It initializes the activity, see this question for more of an explanation.
If this doesn't fix your problem and you have more code in your second activity, it might be useful to post code for the entire activity.