I have this strange behavior I cannot explain.
My layout is quite simple: An EditText:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<EditText
android:id="#+id/etPass"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
When I try to longPress it (to paste some text) I got an imediate Force Close and this error:
05-08 16:56:16.838: E/AndroidRuntime(12164): FATAL EXCEPTION: main
05-08 16:56:16.838: E/AndroidRuntime(12164): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-08 16:56:16.838: E/AndroidRuntime(12164): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:2995)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$PinnedPopupWindow.<init>(Editor.java:2280)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2968)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$ActionPopupWindow.<init>(Editor.java:2968)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$HandleView.showActionPopupWindow(Editor.java:3189)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$InsertionHandleView.showWithActionPopup(Editor.java:3416)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$InsertionPointCursorController.showWithActionPopup(Editor.java:3652)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor.performLongClick(Editor.java:870)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.TextView.performLongClick(TextView.java:7973)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.View$CheckForLongPress.run(View.java:17140)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.os.Handler.handleCallback(Handler.java:615)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.os.Looper.loop(Looper.java:213)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.app.ActivityThread.main(ActivityThread.java:4786)
05-08 16:56:16.838: E/AndroidRuntime(12164): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 16:56:16.838: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
05-08 16:56:16.838: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
05-08 16:56:16.838: E/AndroidRuntime(12164): at dalvik.system.NativeStart.main(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164): Caused by: java.lang.reflect.InvocationTargetException
05-08 16:56:16.838: E/AndroidRuntime(12164): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 16:56:16.838: E/AndroidRuntime(12164): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-08 16:56:16.838: E/AndroidRuntime(12164): ... 25 more
05-08 16:56:16.838: E/AndroidRuntime(12164): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=15; index=491
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.content.res.StringBlock.get(StringBlock.java:64)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.content.res.TypedArray.getString(TypedArray.java:124)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.TextView.<init>(TextView.java:800)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.TextView.<init>(TextView.java:450)
05-08 16:56:16.838: E/AndroidRuntime(12164): ... 28 more
I have really no clue what's happening, and I would be pleased to get some help!
Just to be clear, I have nothing in my Activity related to a listener on this EditText:
import android.app.Activity;
import android.os.Bundle;
public class ProActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_pro);
}
}
Just remove this line from your custom style
This single line:
<item name="android:fontFamily">sans-serif-light</item>
Will make the EditText crash when long pressing it.
The Android copy/paste popup was the root cause of the error.
this link solved my issue, although the auto-complete in xml files was not working, but the code in this example is correct, i declared all in the same styles file and it worked :
https://github.com/rengwuxian/MaterialEditText/issues/162
and that's what was said in it :
Seems to be an error in styles, verify if you have
<item name="android:fontFamily"></item>
in your application theme, not in the themes view, in application theme.
The same error happened to me until i removed this line of my style.xml, if you have that line, remove them, if you need this property, you can stylize textviews and buttons with:
<style name="TextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-medium</item>
</style>
<style name="ButtonStyle" parent="android:Widget.Holo.Button">
<item name="android:fontFamily">sans-serif-medium</item>
</style>
And in your app theme, use:
<item name="android:textViewStyle">#style/TextViewStyle</item>
<item name="android:buttonStyle">#style/ButtonStyle</item>
I have also encountered this problem ;
but the cause of it is that i use ContextThemeWrapper;
here is how we get LayoutInflater from ContextThemeWrapper
#Override
public Object getSystemService(String name) {
if (LAYOUT_INFLATER_SERVICE.equals(name)) {
if (mInflater == null) {
mInflater = LayoutInflater.from(mBase).cloneInContext(this);
}
return mInflater;
}
return mBase.getSystemService(name);
}
from the code block above, we can see that it handle LayoutInflater specially, which is the source of the problem.
my solution is : override this method as follow
#Override
public Object getSystemService(String name){
return getBaseContext().getSystemService(name);
}
I face this problem when using <item name="android:fontFamily">sans-serif</item> in style.xml
It CRASH on
Samsung S4 (SC-04E) (5.0.1)
Samsung Galaxy Node 5 (5.1.1)
It NOT CRASH on
Samsung S7 Edge (SM-G935F) (7.0)
Xiaomi A2 (8.0.1)
Pixel XL (8.1.0)
Sony Xperia Z5 Au (SOV32) (6.0)
Arrow NX (F-04G) (6.0.1)
Kyocera (S2) (7.0)
At first, I think this problem will only happened on Samsung but Samsung S7 don't crash.
Then I think the API may cause this problem because current crash device have API < 6.0. However I am not sure about it because I don't have much device for testing
Summary: It will crash in some device
TO FIX THIS PROBLEM
First, remove sans-serif
Then download Roboto font from https://github.com/google/fonts/tree/master/apache/roboto then add to project following https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml
Why Roboto font?
You are facing this problem when using sans-serif font right?
sans-serif in Android is Roboto font (see here Android default font)
If you know some device which will crash, please edit my answer, it may help for testing.
Hope it help
Related
I download the example from here. I imported the project in eclipse, added support library v4 to build path. When I run the app, it always crashes. This is the error in LogCat: Could anyone please help me? Thanks.
05-08 22:39:41.396: E/dalvikvm(22444): Could not find class 'com.example.android.scheduler.SampleAlarmReceiver', referenced from method com.example.android.scheduler.MainActivity.<init>
05-08 22:39:41.406: E/AndroidRuntime(22444): FATAL EXCEPTION: main
05-08 22:39:41.406: E/AndroidRuntime(22444): java.lang.NoClassDefFoundError: com.example.android.scheduler.SampleAlarmReceiver
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.example.android.scheduler.MainActivity.<init>(MainActivity.java:34)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.Class.newInstanceImpl(Native Method)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.Class.newInstance(Class.java:1319)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2521)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.access$600(ActivityThread.java:162)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1370)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.os.Looper.loop(Looper.java:158)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.main(ActivityThread.java:5777)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
05-08 22:39:41.406: E/AndroidRuntime(22444): at dalvik.system.NativeStart.main(Native Method)
I got the same issue when I added support v4 lib via "add external jar" in build path.
To solve it:
remove the support v4 lib from build path
create a directory named "libs" in the root on the project
copy the lib into the newly created directory.
Eclipse should now show a new "library directory" in your project called "Android Private Libraries" which include support library v4
Refresh, clean ... and it should work.
My app crashes and gives me the following trace:
05-08 08:49:15.228: E/AndroidRuntime(1022): FATAL EXCEPTION: main
05-08 08:49:15.228: E/AndroidRuntime(1022): java.lang.IllegalStateException: Activity has been destroyed
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1365)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:578)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:161)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:965)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:811)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.setAdapter(VerticalViewPager.java:334)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting.assign_vertical_gangs_swipping(Lighting.java:505)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting.select_room(Lighting.java:403)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting$11.onClick(Lighting.java:351)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.view.View.performClick(View.java:4084)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.view.View$PerformClick.run(View.java:16966)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Handler.handleCallback(Handler.java:615)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Looper.loop(Looper.java:137)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-08 08:49:15.228: E/AndroidRuntime(1022): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 08:49:15.228: E/AndroidRuntime(1022): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-08 08:49:15.228: E/AndroidRuntime(1022): at dalvik.system.NativeStart.main(Native Method)
The point is I can't deal with that Activity Destroy thing as the Activity is Destroyed without calling onDestroy() method and I figured that because I override the onDestroy method but it didn't go through it, also I checked the isDestroyed() output but the strange thing it even not giving me true despite I put the Line that makes the Activity crashes in a try-ctach block, and prints isDestroyed in the catch block (which can mean that that line itself is the one which makes the Activity crashes) and here's the code area that the app crashes in:
List<Fragment> temp_fragments = fragments; // list of fragments to add to a VerticalViewPager and return it through pageAdapter
TabAdapter2 = new LightVerticalPageAdapter(super.getSupportFragmentManager(), temp_fragments);
Tab2 = (VerticalViewPager) SomeFragment.views.findViewById(R.id.vertical_pager);// "SomeFragment" is the fragment that contains the VerticalPager and the "views" var is the var that stores Fragmrnt view when hitting fragment onViewCreated at the first time
Tab2.setAdapter(TabAdapter2); // HERE IS WHERE THE APP CRASHES AND NOT CALLS ACTIVITY onDestroy()
I'm creating a native extension that shows a native Google Map from a Flex-based AIR application. You can watch lee brimelow's demo to get the idea: https://plus.google.com/110495278155587072613/posts/degSYVx8423
I got a working demo of a native extension, just to show an Activity with some buttons, but I got stuck when I tried to show the map. Here is the exception I'm getting on setContentView(layoutID):
05-08 11:48:40.624: I/System.out(27917): WebViewActivity.onCreate failed with error:
05-08 11:48:40.634: I/System.out(27917): "android.view.InflateException: Binary XML file line #9: Error inflating class fragment"
05-08 11:48:40.644: W/dalvikvm(27917): threadid=1: thread exiting with uncaught exception (group=0x40fd8468)
05-08 11:48:40.654: E/AndroidRuntime(27917): FATAL EXCEPTION: main
05-08 11:48:40.654: E/AndroidRuntime(27917): java.lang.RuntimeException: Unable to start activity ComponentInfo{air.GoogleMapsApp.debug/com.trasys.googlemaps.WebViewActivity}: java.lang.RuntimeException: Attempting to create multiple DataRequestDispatchers
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread.access$600(ActivityThread.java:151)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.os.Looper.loop(Looper.java:155)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread.main(ActivityThread.java:5454)
05-08 11:48:40.654: E/AndroidRuntime(27917): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 11:48:40.654: E/AndroidRuntime(27917): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
05-08 11:48:40.654: E/AndroidRuntime(27917): at dalvik.system.NativeStart.main(Native Method)
05-08 11:48:40.654: E/AndroidRuntime(27917): Caused by: java.lang.RuntimeException: Attempting to create multiple DataRequestDispatchers
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.ak.n.b(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.ak.n.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.ak.h.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.af.w.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.ab.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.ab.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.ag.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.ag.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.bw.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at maps.z.r.onCreateView(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.os.Binder.transact(Binder.java:326)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.internal.e$4.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.internal.e.a(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.internal.e.onCreateView(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:809)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1037)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1804)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.Activity.performCreate(Activity.java:5069)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
05-08 11:48:40.654: E/AndroidRuntime(27917): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
05-08 11:48:40.654: E/AndroidRuntime(27917): ... 11 more
I'm pretty convinced the communication between AIR and Android is ok, so I'm only posting my native code. (When I remove the map, the native extension works with no issues)
Here is the layout xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<fragment android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="300dp" />
</LinearLayout>
Here is my FREFunction
public class GoogleMapsFunction implements FREFunction {
#Override
public FREObject call(FREContext ctx, FREObject[] passedArgs) {
int layoutID, googleMapID;
Intent i = new Intent(ctx.getActivity(), WebViewActivity.class);
layoutID = ctx.getResourceId("layout.activity_google_maps");
googleMapID = ctx.getResourceId("id.map");
i.putExtra("layoutID", layoutID);
i.putExtra("googleMapID", googleMapID);
ctx.getActivity().startActivity(i);
return null;
}
}
Here is my Activity
public class WebViewActivity extends Activity {
private GoogleMap map;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
int layoutID = getIntent().getIntExtra("layoutID", -1);
setContentView(layoutID);
int googleMapID = getIntent().getIntExtra("googleMapID", -1);
map = ((MapFragment) getFragmentManager().findFragmentById(googleMapID))
.getMap();
} catch(Exception e){
System.out.printf("WebViewActivity.onCreate failed with error:\n\"%s\"\n",
e.toString());
Toast.makeText(this, "WebViewActivity.onCreate failed: " +
e.toString(), Toast.LENGTH_SHORT).show();
}
}
}
Here is my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trasys.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<permission android:name="com.example.helloworld.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.helloworld.permission.C2D_MESSAGE" />
<permission android:name="com.example.helloworld.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.helloworld.permission.MAPS_RECEIVE"/>
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MyApiKey"/>
</application>
</manifest>
I see some com.google.android.gms. entries in the stacktrace, so I assume all google libraries are loaded correctly.
I created a separate pure native android application for testing purpose.
In this app I managed to create an activity which displays the map, this activity uses the same layout XML, the same google libraries and the same API key.
Any idea's?
You need to include third party classes on the jar file that is why fragment class is not found "Error inflating class fragment" .
After exporting your java files open the jar file with any zip tool like 7-zip, browse to com folder and copy the packages from third party jar file (opening it same way). After that you will need to recreate the ane file.
I am working on Map view using android API v2, I am following this tutorial, I have followed what he explained in tutorial, but still I am getting Fatal exception. here is my xml code with log cat.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
logcat:
05-08 10:38:22.121: E/AndroidRuntime(954): FATAL EXCEPTION: main
05-08 10:38:22.121: E/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.map/com.example.map.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:137)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.setContentView(Activity.java:1881)
05-08 10:38:22.121: E/AndroidRuntime(954): at com.example.map.MainActivity.onCreate(MainActivity.java:12)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.performCreate(Activity.java:5104)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 11 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:592)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:560)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Activity.onCreateView(Activity.java:4709)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 21 more
05-08 10:38:22.121: E/AndroidRuntime(954): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk
05-08 10:38:22.121: E/AndroidRuntime(954): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-08 10:38:22.121: E/AndroidRuntime(954): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-08 10:38:22.121: E/AndroidRuntime(954): at android.app.Fragment.instantiate(Fragment.java:582)
05-08 10:38:22.121: E/AndroidRuntime(954): ... 24 more
And my manifest is looks like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.example.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDSW0CfwDN0LyrF8PBeihEjrAkj25TDhUQ" />
</application>
</manifest>
You are trying to import existing project into library. You should be importing the library using following method.
Right click package explorer. Import -> Expand Android -> Existing
Android Code Into Workspace.
Select the google-play-services library. And check the copy to
workspace checkbox.
Once this is done. Reference the library project
Right click on the project. Select Android in the left pane. In the right pane bottom you would see a frame with label Library. Click on add and add the imported library.
To add support library to your project:
Right click on the project Androids Tools -> Add Support library.
If you decide to use support libraries you will have to replace the code
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
with
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
also in your java file you will have to use SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
Make sure that you are using Google APIs in the project build target. Go to project Properties > Android to check this.
Are you using the correct API (GOOGLE API) in Eclipse? Make sure to use the GOOGLE APIs if you want to use google maps in android!
You are probably having an import problem. Just check in right click on project -> properties -> Java build path you have imported the libs. See this link for clarity
This error is usually derived from incorrect referencing of google-play-services library.
To do it correctly please follow the first 3 steps of this blog post guide I wrote on integrating Google Maps API V2 in your application:
Google Maps API V2
""Caused by: java.lang.ClassNotFoundException: Didn't find class"com.google.android.gms.maps.MapFragment" on path: /data/app/com.example.map-2.apk""
Have you checked this?
I think you should Add this (com.google.android.gms.maps.MapFragment)ACTIVITY in your AndroidManifest.XML.
Give a try to the three "caused by..." errors in the LogCat.
This is an Android Development related question.
I make use of the ADT and Eclipse Indigo in a Windows 7 64bits
First we have the xml layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
</LinearLayout>
Second, we have the class that makes a reference to the xml file right above
package com.example.test_table;
import android.os.Bundle;
import android.app.Activity;
public class Home extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
}
In third place, we got the declaration in the manifest of the class Home
<activity
android:name="com.example.test_table.Home"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And then, when I try to run, Eclipse returns a nullpointerexception.
But when I remove the EditText from the xml layout file, the application works.
This problem suddenly appeared in my computer and I'm trying to do something about it.
LogCat:
02-27 22:42:39.051: E/AndroidRuntime(12164): FATAL EXCEPTION: main
02-27 22:42:39.051: E/AndroidRuntime(12164): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.test_table/com.example.test_table.Home}: java.lang.NullPointerException
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.access$600(ActivityThread.java:128)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.os.Looper.loop(Looper.java:137)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.main(ActivityThread.java:4514)
02-27 22:42:39.051: E/AndroidRuntime(12164): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 22:42:39.051: E/AndroidRuntime(12164): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
02-27 22:42:39.051: E/AndroidRuntime(12164): at dalvik.system.NativeStart.main(Native Method)
02-27 22:42:39.051: E/AndroidRuntime(12164): Caused by: java.lang.NullPointerException
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.sec.clipboard.ClipboardExManager.updateData(ClipboardExManager.java:241)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.widget.EditText.onFocusChanged(EditText.java:134)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.handleFocusGainInternal(View.java:3727)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5420)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5370)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.View.requestFocus(View.java:5348)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.parseRequestFocus(LayoutInflater.java:753)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Activity.setContentView(Activity.java:1835)
02-27 22:42:39.051: E/AndroidRuntime(12164): at com.example.test_table.Home.onCreate(Home.java:11)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Activity.performCreate(Activity.java:4465)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
02-27 22:42:39.051: E/AndroidRuntime(12164): ... 11 more
So, I'd like to know what causes the ADT to stop recognizing an Edittext?
What is strange to me is this log:
02-27 22:42:39.051: E/AndroidRuntime(12164): at android.sec.clipboard.ClipboardExManager.updateData(ClipboardExManager.java:241)
Putting that into a Google search seems to pull results about a bug in Samsung devices and the soft keyboard. I am assuming that is what you are using because it does not look like any non-Samsung results are appearing. I would look into this bug, and possibly try to disable the keyboard from appearing when the application is first launched. This may stop it from crashing in onCreate() until you actually focus the EditText by clicking it. Putting Something like this in onCreate() can help you out with that:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Like I said in my comment, your code is correct. Try testing it on the emulator or another Android device. I will try to help you further if anything else comes up.
Here are some of the links I skimmed through:
https://code.google.com/p/android/issues/detail?id=35358
http://forum.xda-developers.com/showthread.php?t=1655619
https://code.google.com/p/android/issues/detail?id=36322
try using edit text in your java file and refer it
EditText edt = (EditText) findViewById(path);