Trying to implement CountryPicker from github. No errors in code, app crashes, a lot of logcat errors
-
21-12-2019 - |
Question
It seems that I am asking something that has been asked in the past, but nobody else managed to get an answer for, therefore fingers crossed.
I am trying to implement the CountryPicker from github. However it doesn't seem to work. I had tried 2 out 3 possible ways to implement it (at least I think there were 3).
- First one was to add the CountryPicker code inside my application and on top of that implement the sample folder code (didnt work)
- Second one was to somehow change the fragmentactivity code to activity (havent tried that yet)
- Third one was to import the CountryPicker code as a library. I think that was the right way to do it, therefore I have listed the steps I have done to make it work.
First I have created new android project called CountryPickerApp and implemented the code from the sample folder found within that countrypicker repository. Here's the code for MainActivity.class:
package com.example.countrypickerapp; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.view.Menu; import android.view.MenuItem; import android.view.MenuItem.OnMenuItemClickListener; import android.widget.Toast; import com.countrypicker.CountryPicker; import com.countrypicker.CountryPickerListener; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); CountryPicker picker = new CountryPicker(); picker.setListener(new CountryPickerListener() { @Override public void onSelectCountry(String name, String code) { Toast.makeText( MainActivity.this, "Country Name: " + name + " - Code: " + code + " - Currency: " + CountryPicker.getCurrencyCode(code), Toast.LENGTH_SHORT).show(); } }); transaction.replace(R.id.home, picker); transaction.commit(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); MenuItem item = menu.findItem(R.id.show_dialog); item.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { CountryPicker picker = CountryPicker.newInstance("Select Country"); picker.setListener(new CountryPickerListener() { @Override public void onSelectCountry(String name, String code) { Toast.makeText( MainActivity.this, "Country Name: " + name + " - Code: " + code + " - Currency: " + CountryPicker.getCurrencyCode(code), Toast.LENGTH_SHORT).show(); } }); picker.show(getSupportFragmentManager(), "COUNTRY_PICKER"); return false; } }); return true; }
}
Here's the code for the AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.countrypickerapp" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.countrypickerapp.Main1Activity" android:label="@string/app_name" android:parentActivityName="@string/title_activity_main1"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.countrypickerapp.MainActivity" android:label="@string/title_activity_main1" > </activity> </application> </manifest>
As far as I understood the main folder (CountryPicker) had to be imported as a library so i followed those steps:
File->New->Other Select Android Project Select "Create Project from existing source" Click "Browse..." button and navigate to johannilsson-android-actionbar\actionbar Finish (Now action bar project in your workspace) Right-click on your project -> Properties In Android->Library section click Add select recently added project -> Ok
And here is the list of logcat log errors:
11-17 02:06:37.320: I/SurfaceTextureClient(9657): [STC::queueBuffer] this:0x4fa637f8, api:1, last queue time elapsed :5603 ms 11-17 02:06:37.321: I/SurfaceTextureClient(9657): [0x4fa637f8] frames:2, duration:5.603000, fps:0.356932 11-17 02:06:37.325: W/MMUMapper(9657): fail to register MVA, unsupported format(0x5) 11-17 02:06:37.413: W/ActionMenuPresenter(9657): showOverflowMenu fail, mReserveOverflow=true, mMenu.getNonActionItems().size()=1, isOverflowMenuShowing()=false 11-17 02:06:37.476: W/MMUMapper(9657): fail to register MVA, unsupported format(0x5) 11-17 02:06:37.490: W/MMUMapper(9657): fail to register MVA, unsupported format(0x5) 11-17 02:06:37.510: W/MMUMapper(9657): fail to register MVA, unsupported format(0x5) 11-17 02:06:38.094: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x52b85000) size(57344) f(0x5) 11-17 02:06:38.094: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x52cec000) size(57344) f(0x5) 11-17 02:06:38.095: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x52cfa000) size(57344) f(0x5) 11-17 02:06:38.102: W/InputEventReceiver(9657): Attempted to finish an input event but the input event receiver has already been disposed. 11-17 02:06:40.889: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x528cf000) size(614400) f(0x5) 11-17 02:06:40.890: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x52d6d000) size(614400) f(0x5) 11-17 02:06:40.890: W/MMUMapper(9657): invalid operation for unregister MVA with VA(0x52aa9000) size(614400) f(0x5) 11-17 02:10:40.214: E/Trace(10401): error opening trace file: No such file or directory (2) 11-17 02:10:40.316: W/dalvikvm(10401): Unable to resolve superclass of Lcom/example/countrypickerapp/MainActivity; (11) 11-17 02:10:40.316: W/dalvikvm(10401): Link of class 'Lcom/example/countrypickerapp/MainActivity;' failed 11-17 02:10:40.317: E/dalvikvm(10401): Could not find class 'com.example.countrypickerapp.MainActivity', referenced from method com.example.countrypickerapp.Main1Activity$1.onClick 11-17 02:10:40.317: W/dalvikvm(10401): VFY: unable to resolve const-class 57 (Lcom/example/countrypickerapp/MainActivity;) in Lcom/example/countrypickerapp/Main1Activity$1; 11-17 02:10:40.505: W/MMUMapper(10401): fail to register MVA, unsupported format(0x5) 11-17 02:10:40.615: W/MMUMapper(10401): fail to register MVA, unsupported format(0x5) 11-17 02:10:42.480: I/SurfaceTextureClient(10401): [0x4fa637f8] frames:2, duration:1.945000, fps:1.027828 11-17 02:10:42.499: W/MMUMapper(10401): fail to register MVA, unsupported format(0x5) 11-17 02:10:42.619: W/dalvikvm(10401): threadid=1: thread exiting with uncaught exception (group=0x41269908) 11-17 02:10:42.638: E/AndroidRuntime(10401): FATAL EXCEPTION: main 11-17 02:10:42.638: E/AndroidRuntime(10401): java.lang.NoClassDefFoundError: com.example.countrypickerapp.MainActivity 11-17 02:10:42.638: E/AndroidRuntime(10401): at com.example.countrypickerapp.Main1Activity$1.onClick(Main1Activity.java:22) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.view.View.performClick(View.java:4091) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.view.View$PerformClick.run(View.java:17072) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.os.Handler.handleCallback(Handler.java:615) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.os.Handler.dispatchMessage(Handler.java:92) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.os.Looper.loop(Looper.java:153) 11-17 02:10:42.638: E/AndroidRuntime(10401): at android.app.ActivityThread.main(ActivityThread.java:5037) 11-17 02:10:42.638: E/AndroidRuntime(10401): at java.lang.reflect.Method.invokeNative(Native Method) 11-17 02:10:42.638: E/AndroidRuntime(10401): at java.lang.reflect.Method.invoke(Method.java:511) 11-17 02:10:42.638: E/AndroidRuntime(10401): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 11-17 02:10:42.638: E/AndroidRuntime(10401): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:588) 11-17 02:10:42.638: E/AndroidRuntime(10401): at dalvik.system.NativeStart.main(Native Method)
Additonally I have added an additional Activity called MainActivity1 which has a button, which when clicked redirects to MainActivity where CountryPicker is implemented.
I hope I have explained my problem well and will get either a solution, tip, hint or anything which could get me closer to getting it to work. I know that I could have reimplemented all of it from scratch using different methods, but I don't see a point of reinventing something that has been already been implemented and uploaded for sharing, apart from learning something new of course.
Solution
Your manifest declares Main 1 Activity (space added to highlight the numeric 1) but your class file is MainActivity.java without the 1 !! :)