I am trying to use Google Map in my Android app using Google API V2; I tried the app on my HTC desire phone, but it keeps on crashing. I have tried changing the Project Build Target to Android 2.2 and Android 4.2, but still no luck. I have also added the android-support-v4.jar to my project. I have tried to follow these Link
Here are my codes:
googleMaps.manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.luiz.googleMaps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.luiz.googleMaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.luiz.googleMaps.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="I have used my keys;com.luiz.googleMaps" />
<activity
android:name="com.luiz.googleMaps.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>
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"
class="com.google.android.gms.maps.SuppportMapFragment"/>
MainActivity
package com.luiz.googleMaps;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
public class MainActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
LogCat Error:
12-21 06:08:30.734: D/dalvikvm(7102): GC_EXTERNAL_ALLOC freed 54K, 50% free 2692K/5379K, external 0K/0K, paused 93ms
12-21 06:08:30.754: E/ActivityThread(7102): Failed to inflate
12-21 06:08:30.754: E/ActivityThread(7102): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:08:30.754: E/ActivityThread(7102): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:31)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:08:30.754: E/ActivityThread(7102): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:08:30.754: E/ActivityThread(7102): at android.os.Looper.loop(Looper.java:130)
12-21 06:08:30.754: E/ActivityThread(7102): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:08:30.754: E/ActivityThread(7102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:08:30.754: E/ActivityThread(7102): at dalvik.system.NativeStart.main(Native Method)
12-21 06:08:30.754: E/ActivityThread(7102): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:08:30.754: E/ActivityThread(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:08:30.754: E/ActivityThread(7102): ... 19 more
12-21 06:08:30.754: E/ActivityThread(7102): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-2.apk]
12-21 06:08:30.754: E/ActivityThread(7102): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:08:30.754: E/ActivityThread(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:08:30.754: E/ActivityThread(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:08:30.754: E/ActivityThread(7102): ... 22 more
12-21 06:08:30.764: D/AndroidRuntime(7102): Shutting down VM
12-21 06:08:30.764: W/dalvikvm(7102): threadid=1: thread exiting with uncaught exception (group=0x40128560)
12-21 06:08:30.764: E/AndroidRuntime(7102): FATAL EXCEPTION: main
12-21 06:08:30.764: E/AndroidRuntime(7102): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luiz.googleMaps/com.luiz.googleMaps.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.os.Looper.loop(Looper.java:130)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:08:30.764: E/AndroidRuntime(7102): at dalvik.system.NativeStart.main(Native Method)
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:08:30.764: E/AndroidRuntime(7102): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:31)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 11 more
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 19 more
12-21 06:08:30.764: E/AndroidRuntime(7102): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-2.apk]
12-21 06:08:30.764: E/AndroidRuntime(7102): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:08:30.764: E/AndroidRuntime(7102): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:08:30.764: E/AndroidRuntime(7102): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:08:30.764: E/AndroidRuntime(7102): ... 22 more
12-21 06:08:36.299: I/Process(7102): Sending signal. PID: 7102 SIG: 9
12-21 06:18:46.745: D/dalvikvm(7174): GC_EXTERNAL_ALLOC freed 55K, 50% free 2691K/5379K, external 0K/0K, paused 45ms
12-21 06:18:46.765: E/ActivityThread(7174): Failed to inflate
12-21 06:18:46.765: E/ActivityThread(7174): android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:18:46.765: E/ActivityThread(7174): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:15)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:18:46.765: E/ActivityThread(7174): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:18:46.765: E/ActivityThread(7174): at android.os.Looper.loop(Looper.java:130)
12-21 06:18:46.765: E/ActivityThread(7174): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:18:46.765: E/ActivityThread(7174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:18:46.765: E/ActivityThread(7174): at dalvik.system.NativeStart.main(Native Method)
12-21 06:18:46.765: E/ActivityThread(7174): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:18:46.765: E/ActivityThread(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:18:46.765: E/ActivityThread(7174): ... 19 more
12-21 06:18:46.765: E/ActivityThread(7174): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-1.apk]
12-21 06:18:46.765: E/ActivityThread(7174): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:18:46.765: E/ActivityThread(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:18:46.765: E/ActivityThread(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:18:46.765: E/ActivityThread(7174): ... 22 more
12-21 06:18:46.775: D/AndroidRuntime(7174): Shutting down VM
12-21 06:18:46.775: W/dalvikvm(7174): threadid=1: thread exiting with uncaught exception (group=0x40128560)
12-21 06:18:46.775: E/AndroidRuntime(7174): FATAL EXCEPTION: main
12-21 06:18:46.775: E/AndroidRuntime(7174): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.luiz.googleMaps/com.luiz.googleMaps.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.os.Looper.loop(Looper.java:130)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.reflect.Method.invoke(Method.java:507)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-21 06:18:46.775: E/AndroidRuntime(7174): at dalvik.system.NativeStart.main(Native Method)
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:213)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.Activity.setContentView(Activity.java:1657)
12-21 06:18:46.775: E/AndroidRuntime(7174): at com.luiz.googleMaps.MainActivity.onCreate(MainActivity.java:15)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 11 more
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SuppportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 19 more
12-21 06:18:46.775: E/AndroidRuntime(7174): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SuppportMapFragment in loader dalvik.system.PathClassLoader[/data/app/com.luiz.googleMaps-1.apk]
12-21 06:18:46.775: E/AndroidRuntime(7174): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-21 06:18:46.775: E/AndroidRuntime(7174): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-21 06:18:46.775: E/AndroidRuntime(7174): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
12-21 06:18:46.775: E/AndroidRuntime(7174): ... 22 more
12-21 06:23:46.827: I/Process(7174): Sending signal. PID: 7174 SIG: 9
Have you tried using MapFragment instead of using SupportMapFragment.
My main activity looks like this
public class MapActivity extends Activity {
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapactivity);
this.getActionBar().setTitle("Map");
getActionBar().setDisplayHomeAsUpEnabled(true);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Have you included the android-support-v4.jar & google-play-services.jar in your application?
If yes then just remove the fully qualified name of activity tag to as follow:
`<activity
android:name=".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>`
I think you should check if Google play service is available first.
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
// what you want to do
}
Related
i'm trying to instantiate a Dialog in my Activity.
public void createOptionsMenu() {
Log.e("ActivityContext null?","" + myActivity.this);
myOptionsDialog = new Dialog(myActivity.this); //throwsNPE
myOptionsDialog.setContentView(R.layout.options_dialog);
myOptionsDialog.show();
}
Due to the Log.e which you can see above i know that my activity-context is not null!
12-21 15:17:15.466: E/ActivityContext null?(3774): com.android.myproject.myActivity#41fd9af0
12-21 15:17:15.469: E/AndroidRuntime(3774): java.lang.NullPointerException
I think to Problem is that i call createOptionsMenu() from a different class which only has the ApplicationContext from myActivity. If so, how can i create my Dialog without passing the ActivityContext to the other class which calls createOptionsMenu.
Any help is appreciated.
Update:
12-21 15:17:15.469: E/AndroidRuntime(3774): FATAL EXCEPTION: main
12-21 15:17:15.469: E/AndroidRuntime(3774): java.lang.NullPointerException
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:140)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:103)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.app.Dialog.<init>(Dialog.java:154)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.app.Dialog.<init>(Dialog.java:131)
12-21 15:17:15.469: E/AndroidRuntime(3774): at com.android.myproject.myActivity.createOptionsMenu(myActivity.java:798)
12-21 15:17:15.469: E/AndroidRuntime(3774): at com.android.myproject.WorkerClass$2.onItemLongClick(WorkerClass.java:448)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.widget.AbsListView.performLongPress(AbsListView.java:2883)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2833)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.os.Handler.handleCallback(Handler.java:725)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.os.Looper.loop(Looper.java:153)
12-21 15:17:15.469: E/AndroidRuntime(3774): at android.app.ActivityThread.main(ActivityThread.java:5338)
12-21 15:17:15.469: E/AndroidRuntime(3774): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:17:15.469: E/AndroidRuntime(3774): at java.lang.reflect.Method.invoke(Method.java:511)
12-21 15:17:15.469: E/AndroidRuntime(3774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12-21 15:17:15.469: E/AndroidRuntime(3774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-21 15:17:15.469: E/AndroidRuntime(3774): at dalvik.system.NativeStart.main(Native Method)
Instantiate Activity:
myActivity myActivity_ = new myActivity();
WeakReference<myActivity> myWeakActivity = new WeakReference<myActivity>(myActivity_);
myWeakActivity.get().createOptionsMenu();
The Problem was the Context. As i created a new Object of my Activity the old Activity isn't valid "inside" the new Object.
The soltuion was to simply pass the Activity-Context to createOptionsMenu and then do this:
MyActivity myActivity_ = (MyActivity) context;
Then you have a reference to the resources you really want.
Hope it helps somebody.
This question already has answers here:
Google Play Services update
(6 answers)
Closed 3 years ago.
12-21 02:04:02.430: E/AndroidRuntime(1690): FATAL EXCEPTION: main
12-21 02:04:02.430: E/AndroidRuntime(1690): Process: com.example.main, PID: 1690
12-21 02:04:02.430: E/AndroidRuntime(1690): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.main/com.example.main.ShowRouteMap}: android.view.InflateException: Binary XML file line #66: Error inflating class fragment
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.os.Handler.dispatchMessage(Handler.java:102)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.os.Looper.loop(Looper.java:137)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-21 02:04:02.430: E/AndroidRuntime(1690): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 02:04:02.430: E/AndroidRuntime(1690): at java.lang.reflect.Method.invoke(Method.java:515)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-21 02:04:02.430: E/AndroidRuntime(1690): at dalvik.system.NativeStart.main(Native Method)
12-21 02:04:02.430: E/AndroidRuntime(1690): Caused by: android.view.InflateException: Binary XML file line #66: Error inflating class fragment
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.Activity.setContentView(Activity.java:1928)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.example.main.ShowRouteMap.onCreate(ShowRouteMap.java:19)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.Activity.performCreate(Activity.java:5243)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-21 02:04:02.430: E/AndroidRuntime(1690): ... 11 more
12-21 02:04:02.430: E/AndroidRuntime(1690): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
12-21 02:04:02.430: E/AndroidRuntime(1690): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-21 02:04:02.430: E/AndroidRuntime(1690): ... 21 more
you can see your log line
12-21 02:04:02.430: E/AndroidRuntime(1690): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
Solution
just put this in your AndroidManifist.xml under application tag
<meta-data
android:name="com.google.android.gms.version"
android:value="4030500" />
My reports provide me this error but I can't understand how is it possible?
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.aviascanner.aviascanner/net.aviascanner.aviascanner.ui.activities.GetCitiesActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3905)
at android.app.ActivityThread.access$2600(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at net.aviascanner.aviascanner.ui.activities.GetCitiesActivity.onCreate(GetCitiesActivity.java:115)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
... 12 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.EditText.<init>(EditText.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector_edittext.xml from drawable resource ID #0x7f0200c4
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1901)
at android.widget.TextView.<init>(TextView.java:440)
at android.widget.EditText.<init>(EditText.java:55)
... 29 more
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 33 more
android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at net.aviascanner.aviascanner.ui.activities.GetCitiesActivity.onCreate(GetCitiesActivity.java:115)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3905)
at android.app.ActivityThread.access$2600(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.EditText.<init>(EditText.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 25 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector_edittext.xml from drawable resource ID #0x7f0200c4
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1901)
at android.widget.TextView.<init>(TextView.java:440)
at android.widget.EditText.<init>(EditText.java:55)
... 29 more
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 33 more
java.lang.reflect.InvocationTargetException
at android.widget.EditText.<init>(EditText.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at net.aviascanner.aviascanner.ui.activities.GetCitiesActivity.onCreate(GetCitiesActivity.java:115)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3905)
at android.app.ActivityThread.access$2600(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector_edittext.xml from drawable resource ID #0x7f0200c4
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1901)
at android.widget.TextView.<init>(TextView.java:440)
at android.widget.EditText.<init>(EditText.java:55)
... 29 more
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 33 more
android.content.res.Resources$NotFoundException: File res/drawable/selector_edittext.xml from drawable resource ID #0x7f0200c4
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1901)
at android.widget.TextView.<init>(TextView.java:440)
at android.widget.EditText.<init>(EditText.java:55)
at android.widget.EditText.<init>(EditText.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at net.aviascanner.aviascanner.ui.activities.GetCitiesActivity.onCreate(GetCitiesActivity.java:115)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3905)
at android.app.ActivityThread.access$2600(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 33 more
java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:1901)
at android.widget.TextView.<init>(TextView.java:440)
at android.widget.EditText.<init>(EditText.java:55)
at android.widget.EditText.<init>(EditText.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)
at net.aviascanner.aviascanner.ui.activities.GetCitiesActivity.onCreate(GetCitiesActivity.java:115)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3905)
at android.app.ActivityThread.access$2600(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2121)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
I have found this error in my application also. In my application I solved my problem by making the copies of the drawables in all the folders of the drawables i.e. drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi. This works correctly in my application. Hope this will solve your problem if u have not kept the drawables into all the provided drawable folders.
I am new to android and developing an application that uses the google maps API.
while running the application I have the error :
the application has stopped unexpectedly
Here's what I have in the logcat file :
07-11 01:38:25.751: E/AndroidRuntime(401): FATAL EXCEPTION: main
07-11 01:38:25.751: E/AndroidRuntime(401): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.training.surveyproject/com.training.surveyproject.SurveyActivity}: java.lang.ClassNotFoundException: com.training.surveyproject.SurveyActivity in loader dalvik.system.PathClassLoader[/data/app/com.training.surveyproject-2.apk]
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.os.Looper.loop(Looper.java:123)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-11 01:38:25.751: E/AndroidRuntime(401): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 01:38:25.751: E/AndroidRuntime(401): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 01:38:25.751: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-11 01:38:25.751: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-11 01:38:25.751: E/AndroidRuntime(401): at dalvik.system.NativeStart.main(Native Method)
07-11 01:38:25.751: E/AndroidRuntime(401): Caused by: java.lang.ClassNotFoundException: com.training.surveyproject.SurveyActivity in loader dalvik.system.PathClassLoader[/data/app/com.training.surveyproject-2.apk]
07-11 01:38:25.751: E/AndroidRuntime(401): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-11 01:38:25.751: E/AndroidRuntime(401): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-11 01:38:25.751: E/AndroidRuntime(401): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-11 01:38:25.751: E/AndroidRuntime(401): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-11 01:38:25.751: E/AndroidRuntime(401): ... 11 more
thank you
You must add the activity SurveyActivity to your AndroidManifest.xml file.
You may have also forgotten to add the Google Map Library to the manifest:
<application>
<uses-library android:name="com.google.android.maps" />
</application>
I have an application of which i have use database to insert values on list view . When I run the app on emulator after merging it runs fine but crashes on the device when values begin inserted the LogCat shows me the:close cursor but i have already close all coursers that begin opened.
this the button action
plus.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
tx = txt.getText().toString();
postive.add(tx);
if(tx.length() >0)
{
myDB.execSQL("INSERT INTO UP (ID,UPNAME) VALUES ('"+idnum+"','"+tx+"')");
txt.setText("");
function();
results.clear();
Intent i=new Intent(Positive.this,NewgridActivity.class);
bundle.putInt("tabid", 1);
bundle.putInt("id", idnum);
i.putExtras(bundle);
startActivity(i);
finish();
}
else
DisplayToast("TextField Empty !!!!");
}
});
any help please.
error in logcat
12-21 13:11:02.582: E/Database(4909): close() was never explicitly called on database '/data/data/pa.gd/databases/DECISION_GRID'
12-21 13:11:02.582: E/Database(4909): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
12-21 13:11:02.582: E/Database(4909): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
12-21 13:11:02.582: E/Database(4909): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
12-21 13:11:02.582: E/Database(4909): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
12-21 13:11:02.582: E/Database(4909): at pa.gd.PAIDGRIDActivity.onCreate(PAIDGRIDActivity.java:66)
12-21 13:11:02.582: E/Database(4909): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 13:11:02.582: E/Database(4909): at dalvik.system.NativeStart.main(Native Method)
log error afer closing database
i have close the db when i then try to add i a value it crashes with this log error
12-21 15:45:58.043: E/AndroidRuntime(401): FATAL EXCEPTION: main
12-21 15:45:58.043: E/AndroidRuntime(401): java.lang.IllegalStateException: database not open
12-21 15:45:58.043: E/AndroidRuntime(401): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1723)
12-21 15:45:58.043: E/AndroidRuntime(401): at dc.grd.Positive$1.onClick(Positive.java:77)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.view.View.performClick(View.java:2408)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.view.View$PerformClick.run(View.java:8816)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Handler.handleCallback(Handler.java:587)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.os.Looper.loop(Looper.java:123)
12-21 15:45:58.043: E/AndroidRuntime(401): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:45:58.043: E/AndroidRuntime(401): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:45:58.043: E/AndroidRuntime(401): at java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:45:58.043: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-21 15:45:58.043: E/AndroidRuntime(401): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-21 15:45:58.043: E/AndroidRuntime(401): at dalvik.system.NativeStart.main(Native Method)
Think about a life cycle for you database connection. I recommend to open the db in your application class or in the onResume() method of your activity. Close the db in onPause().
Whenever you work with the database, make sure that all cursors are correctly closed after you are done working with it.
And by the way: Every time you write a question title like you did, a kitten dies...
You seem to be using myDB for your database object. In that case use this to close it: myDB.close();. – Sander van't Veer
<
myDB.close(); the solution give by Sander Vant Veer worked