NPE when instantiate a Dialog - android

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.

Related

In android google map v2 did not start activity.How to solve? [duplicate]

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" />

Bluetooth App Crashes with error FATAL EXCEPTION: main

My Bluetooth application's can already auto request to enable bluetooth but when I did some functionality on my option menu the application will crash right after the bluetooth was turned on.
These were the messages found in the LogCat:
12-21 15:20:08.531: D/BluetoothCommandService(1203): start
12-21 15:20:08.531: D/BluetoothCommandService(1203): setState() 0 -> 1
12-21 15:20:08.581: W/dalvikvm(1203): threadid=1: thread exiting with uncaught exception (group=0x40028870)
12-21 15:20:08.851: E/AndroidRuntime(1203): FATAL EXCEPTION: main
12-21 15:20:08.851: E/AndroidRuntime(1203): java.lang.NullPointerException
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.example.javac101.MainActivity$1.handleMessage(MainActivity.java:171)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.os.Handler.dispatchMessage(Handler.java:95)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.os.Looper.loop(Looper.java:123)
12-21 15:20:08.851: E/AndroidRuntime(1203): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-21 15:20:08.851: E/AndroidRuntime(1203): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:20:08.851: E/AndroidRuntime(1203): at java.lang.reflect.Method.invoke(Method.java:521)
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
12-21 15:20:08.851: E/AndroidRuntime(1203): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-21 15:20:08.851: E/AndroidRuntime(1203): at dalvik.system.NativeStart.main(Native Method)
What would be the possible main cause of this errors?
title might be null here.
Also change
title.setText(R.string.title_notConnected);
to
title.setText(getString(R.string.title_notConnected));

App keeps crashing when using Google API V2

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
}

crash on device

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

Adding googlecalendar events in an android application

I'm a newbie to android programming and have been trying to add events to google calendar via an android application. I found a nice example on the web but cannot seem to get the code to run as the application crashes as soon as the emulator launches. I'm emulating the code on the ANDROID DEVICE (Google APIs/API LEVEL 14).Below is the URL of the code;
http://roman10.net/src/calendarops.zip
Here are the errors which I receive in the logcat;
12-21 15:24:16.602: D/AndroidRuntime(675): Shutting down VM
12-21 15:24:16.612: W/dalvikvm(675): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
12-21 15:24:16.622: E/AndroidRuntime(675): FATAL EXCEPTION: main
12-21 15:24:16.622: E/AndroidRuntime(675): java.lang.RuntimeException: Unable to start activity ComponentInfo{roman10.tutorial.calendarops/roman10.tutorial.calendarops.Main}: android.database.sqlite.SQLiteException: no such column: displayName: , while compiling: SELECT _id, displayName FROM Calendars
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.access$600(ActivityThread.java:122)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.os.Looper.loop(Looper.java:137)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.main(ActivityThread.java:4340)
12-21 15:24:16.622: E/AndroidRuntime(675): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 15:24:16.622: E/AndroidRuntime(675): at java.lang.reflect.Method.invoke(Method.java:511)
12-21 15:24:16.622: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-21 15:24:16.622: E/AndroidRuntime(675): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-21 15:24:16.622: E/AndroidRuntime(675): at dalvik.system.NativeStart.main(Native Method)
12-21 15:24:16.622: E/AndroidRuntime(675): Caused by: android.database.sqlite.SQLiteException: no such column: displayName: , while compiling: SELECT _id, displayName FROM Calendars
12-21 15:24:16.622: E/AndroidRuntime(675): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.content.ContentProviderProxy.query(ContentProviderNative.java:358)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.content.ContentResolver.query(ContentResolver.java:310)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Activity.managedQuery(Activity.java:1706)
12-21 15:24:16.622: E/AndroidRuntime(675): at roman10.tutorial.calendarops.Main.getCalendars(Main.java:127)
12-21 15:24:16.622: E/AndroidRuntime(675): at roman10.tutorial.calendarops.Main.onCreate(Main.java:50)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Activity.performCreate(Activity.java:4465)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
12-21 15:24:16.622: E/AndroidRuntime(675): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
12-21 15:24:16.622: E/AndroidRuntime(675): ... 11 more
Here it is:
android.database.sqlite.SQLiteException: no such column: displayName:
, while compiling: SELECT _id, displayName FROM Calendars
There is no column with the name 'displayName' in your Calendars table.
Since you are using ICS (SDK 14) they have changed the way they handle Calanders and have made a public API. See http://android-developers.blogspot.com/2011/10/ics-and-non-public-apis.html

Categories

Resources