Categories
discuss

Cannot replace default icon in android studio

The image I am trying to replace the default icon with is 512x512px .png.
To change the icon I go app/res [new; image asset;…].
It won’t let me replace or create new icon set in the @drawable.
My most recent thought are that I might not have unlocked some priveges but I am able edit contents of drawable by directly accessing it’s location

Any ideas?

Answer

The new version of android studio put default launcher icon(ic_launcher.png) in mipmap-xxx directories, so just copy and paste your new icon to these directores, and reference it as ‘@mipmap/you_icon’, or in code ‘R.mipmap.you_icon’. If you still want to use the keyword ‘drawable’, then create the drawable folders(drawable-xxx), and put your icon there, and reference it as ‘@drawable/you_icon’, or in code ‘R.drawable.you_icon’

Categories
discuss

Smack throws “NoClassDefFoundError: Failed resolution of: Lorg/jxmpp/util/XmppStringUtils”

I got a problem with my app in which I want to create a simple XMPP client that connects to my server. I got the following problem when I’m starting the app (compilation runs through without problems), but my app closes instantly.

   java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jxmpp/util/XmppStringUtils;
        at org.jivesoftware.smack.provider.ProviderManager.getKey(ProviderManager.java:314)
        at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304)
        at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140)
        at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54)
        at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232)
        at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
        at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
        at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
        at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
        at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
        at org.reisacher.zapp.Main.login(Main.java:30)
        at org.reisacher.zapp.Main.onCreate(Main.java:73)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5257)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jxmpp.util.XmppStringUtils" on path: DexPathList[[zip file "/data/app/org.reisacher.zapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469
at org.jivesoftware.smack.provider.ProviderManager.getKey(ProviderManager.java:314)
at org.jivesoftware.smack.provider.ProviderManager.addStreamFeatureProvider(ProviderManager.java:304)
            at org.jivesoftware.smack.provider.ProviderManager.addLoader(ProviderManager.java:140)
            at org.jivesoftware.smack.initializer.UrlInitializer.initialize(UrlInitializer.java:54)
            at org.jivesoftware.smack.SmackInitialization.loadSmackClass(SmackInitialization.java:232)
            at org.jivesoftware.smack.SmackInitialization.parseClassesToLoad(SmackInitialization.java:193)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:163)
            at org.jivesoftware.smack.SmackInitialization.processConfigFile(SmackInitialization.java:148)
            at org.jivesoftware.smack.SmackInitialization.<clinit>(SmackInitialization.java:116)
            at org.jivesoftware.smack.SmackConfiguration.getVersion(SmackConfiguration.java:96)
            at org.jivesoftware.smack.ConnectionConfiguration.<clinit>(ConnectionConfiguration.java:38)
            at org.reisacher.zapp.Main.login(Main.java:30)
            at org.reisacher.zapp.Main.onCreate(Main.java:73)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.jxmpp.util.XmppStringUtils
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 27 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

But I somehow can’t find anything related to the missing “XmppStringUtils”

This is the code in line 30

public void login() throws XMPPException, IOException, SmackException {
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setServiceName("reisacher.de")
            .setHost("192.168.178.6")
            .setPort(5222)
            .build();

    AbstractXMPPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    connection.login(username, password);
}

And these are my imports

import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

Plus my build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'jetty'
buildscript {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

dependencies {
    compile "org.igniterealtime.smack:smack-android:4.1.1"
    compile "org.igniterealtime.smack:smack-tcp:4.1.1"
    // optional features
    compile "org.igniterealtime.smack:smack-android-extensions:4.1.1"
    compile "org.igniterealtime.smack:smack-core:4.1.1"
}

allprojects {
    repositories {
        jcenter()
    }
}

Thanks

Answer

From NoClassDefFoundError’s javadoc:

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

Java uses dynamic linking, which means that the symbols (class names, …) are linked when first used. As Mohit already pointed out, it appears you are missing the JXMPP library, which is a (transitive) dependency of Smack. I assume you did add Smack to your project by simply putting it into the libs/ folder. This approach is not recommended, as you easily miss a trasitive dependency of Smack, like it happened to you. Instead use a build system which is able to resolve those dependencies like Maven or Gradle. See also:

Categories
discuss

Parcel List of List of Parcelable object

So I’ve parceled lists before, however I’m trying to parcel my GameBoard object, which actually has a List<List<Tile>>. Tile implements parcelable, but I’m not sure exactly how to parcel the List<List>. Here’s what I’ve tried:

public class GameBoard implements Parcelable {
    private String _id;
    public String getId() { return _id; }
    public void setId(String id) { _id = id; }

    private List<List<Tile>> _tiles;
    public List<List<Tile>> getTiles() { return _tiles; }
    public void setTiles(List<List<Tile>> tiles) { _tiles = tiles; }

    public GameBoard(Parcel in) {
        _id = in.readString();
        in.readList(_tiles, ArrayList.class.getClassLoader());
    }

    public GameBoard() {

    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(_id);
        parcel.writeList(_tiles);
    }

    public static final Parcelable.Creator<GameBoard> CREATOR = new Parcelable.Creator<GameBoard>() {
        public GameBoard createFromParcel(Parcel in) {
            return new GameBoard(in);
        }

        public GameBoard[] newArray(int size) {
            return new GameBoard[size];
        }
    };

The tile class correctly implements parcelable, I’m just not exactly sure how to read / write the List<List>> when parceling this class. Any ideas?

Answer

Based on comments, I extended the ArrayList class with my custom class and implemented parcelable:

public class TileList extends ArrayList<Tile> implements Parcelable {

    public TileList(){
        super();
    }

    protected TileList(Parcel in) {
        in.readTypedList(this, Tile.CREATOR);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeTypedList(this);
    }

    public static final Parcelable.Creator<TileList> CREATOR = new Parcelable.Creator<TileList>() {
        public TileList createFromParcel(Parcel in) {
            return new TileList(in);
        }

        public TileList[] newArray(int size) {
            return new TileList[size];
        }
    };
}

and slight changes to my other class:

public class GameBoard implements Parcelable {
    private String _id;
    public String getId() { return _id; }
    public void setId(String id) { _id = id; }

    private List<TileList> _tiles;
    public List<TileList> getTiles() { return _tiles; }
    public void setTiles(List<TileList> tiles) { _tiles = tiles; }

    public GameBoard(Parcel in) {
        _id = in.readString();
        _tiles = new ArrayList<>();
        in.readTypedList(_tiles, TileList.CREATOR);
    }

    public GameBoard() {

    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(_id);
        parcel.writeTypedList(_tiles);
    }

    public static final Parcelable.Creator<GameBoard> CREATOR = new Parcelable.Creator<GameBoard>() {
        public GameBoard createFromParcel(Parcel in) {
            return new GameBoard(in);
        }

        public GameBoard[] newArray(int size) {
            return new GameBoard[size];
        }
    };
}
Categories
discuss

Android Facebook SDK – Share dialog does not respond to cancel callback

I’m working with Facebook sdk 4.0 on my android app and I found this problem:

-when I share a post, I can see the facebook interface and I can post it and cancel it perfectly. I registered the callbacks, but if I press the cancel button, the onCancel callback is not called, the post is not published, but the onSuccess callback is called. However, if I touch the close button, everything works ok.

Here is my code:

 private void fbOnShare(){

    ShareLinkContent shareContent = new ShareLinkContent.Builder()
            .setContentTitle("The Simpson!")
            .setContentUrl(Uri.parse("http://www.foxplay.com/ar/show/6980-los-simpson?gclid=CPa-7N-y7MUCFYMSHwodNLYAKQ"))
            .build();


    this._btnShare = (ShareButton)findViewById(R.id.share_button);
    this._btnShare.setShareContent( shareContent );


    _btnShare.registerCallback( this._fbCallbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

            Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button

        }

        @Override
        public void onCancel() {
            Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
        }

        @Override
        public void onError(FacebookException e) {
            Log.v("MyApp","Share error: " + e.toString());
        }

    });
}

The _fbCallbackManager is created in another method that initializes everything in the onCreate method from the activity.

http://imgur.com/VbMee31

The “Cancelar” button only respond to the onSuccess callback inspite of does not post the share content. The “close” button works ok.

Answer

According to THIS it is not a bug and it should stay that way.

The only way to know if the user accepted the publishing is to check for the postID on the result.

You will only have a postID if the user didn’t cancel AND if the user is logged in to your app AND it has publish permissions. Otherwise it will always be null.

Yeah I know, it sucks.

Categories
discuss

how to remove the logging data from JNativeHook library [closed]

i am trying to use jnativehook library in my project.i want to get a simple data (e.g Mouse Clicked: 2) instead of long loging data that jnativehook is Produced like:

May 31, 2015 9:39:04 PM org.jnativehook.GlobalScreen$NativeHookThread enable INFO: process_button_pressed [339]: Button 1 pressed 2 time(s). (293, 661)

May 31, 2015 9:39:04 PM org.jnativehook.GlobalScreen$NativeHookThread enable

Mouse Clicked: 2

INFO: process_button_released [361]: Button 1 released 2 time(s). (293, 661)

Answer

If you want to remove that logging spam from JNativeHook:

// Clear previous logging configurations.
LogManager.getLogManager().reset();

// Get the logger for "org.jnativehook" and set the level to off.
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);

Adding this to, for example. Your main class construct with remove (almost) all logging. Now let’s detect yourself the events and print some basic information.

First, you have to register the NativeHook:

 GlobalScreen.registerNativeHook();

Then bind some listener to it, for example:

 GlobalScreen.getInstance().addNativeKeyListener(new YourMainClass());

And then override the JNativeHook event methods like this:

@Override
    public void nativeKeyPressed(NativeKeyEvent e) {
System.out.Println(((char) e.getKeyCode()) + " was pressed.")
}

Check out: JNativeHook GitHub, you will find some sample code (for example Global Mouse Listener and documentation about it’s events.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..