Android: Can't get logs with SLF4J-Android - android

I'm building a really simple Android project in ADT and using Maven. I have included both the slf4j-api and slf4j-android dependencies and I can see that everything is compiling properly. However, when I run or debug the application on my Nexus One, I don't see any log output. Is there a specific place I should be looking for these logs or should they be coming out in the Eclipse console?
For reference, here's my main activity:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.app.ListActivity;
import android.os.Bundle;
public class HomeActivity extends ListActivity {
private static Logger logger = LoggerFactory.getLogger(HomeActivity.class);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logger.debug("onCreate");
}
}

Android by default tells slf4j-android to not to log debug messages, and log4j is polite enough to honor that. Use the impolite https://github.com/mvysny/slf4j-handroid instead :)

I use slf4j as well for logging. The log output shows up on the LogCat window. I'm not sure if there's a way to see it in the Eclipse console. In the Eclipse top-level menu, navigate to: Window -> Show View -> Other. When the dialog appears, expand "Android", and select "LogCat". It doesn't show up by default, unfortunately.
HTH,
Kevin

You may want to have a look at using slf4j together with android-logging-log4j. Also see log4j support in Android.

Related

Cannot find Log class in Android

I am developing an app in Android Studio with target for API 22. I have tried to use the Log class with the method d() but I did not find it. The helper shows only Log()...
What am I missing?
Just import the library import android.util.Log;
And just tips: use alt+space and alt+enter feature from Android Studio
Note:
Alt + Enter = Project quick fix (show intention actions and quick fixes)

Android App Error unknownpackageerror

I am creating simple android application in android of hello world printing and getting an -- error Description
Resource Path Location Type Error generating final archive: java.lang.ArrayIndexOutOfBoundsException: 13 Demo_ABC Unknown Android Packaging Problem
Code is:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Someone else had the same problem with eclipse. The solution was to check the box "Create Test Project":
Your project is getting associated with some Test Project which you are not mapping with your newly created project. When you are creating any new project check carefully whether you are including the "Create Test Project" option or not.
Another guess: As the error seems to be package-related and your code does not include that, insert the correct package yourpackage.tld; in the code. (you said "Code is:").
Maybe that is missing Android expects it by default and gives weird errors because that was totally unforseen by the Google Android developers.

ActionBarActivity and FragmentActivity... "Inconvertible types"?

I'm currently having a curious problem, trying to use simultaneously v4 and v7 (actionbar) compatibility libs.
Let's say I've got my own Activity class, that extends ActionBarActivity on one hand and, on the other hand a Fragment, inside of which I call "(MyActivity)getActivity()".
I checked the imports and my Fragment is a v4 Fragment.
In a v4 Fragment, calling "getActivity()" returns a FragmentActivity.
I also checked: ActionBarActivity extends FragmentActivity.
Now here is my problem:
I don't have any error in the editor (no red line).
I'm using Android Studio.
When I try to "Make" the project, the compiler returns an error for each time I call "getActivity" inside my Fragment.
It tells me he has a FragmentActivity but a ActionBarActivity is expected and tells me those classes are incompatible.
It interrupts and I can't even test my app.
It may be a problem with the gradle configuration, but I added "compile "compile "com.android.support:appcompat-v7:18.0.+"" in the "dependencies" part of my build.gradle file, as said on this page:"http://developer.android.com/tools/support-library/setup.html", and it doesn't change anything...
Any idea?
EDIT :
As an adddition to my yesterday's post, even if everything is explain before, here are some code parts and the error message Android-Studio gives me:
First of all, my activity:
...
import android.support.v7.app.ActionBarActivity;
...
public abstract class MyAbstractActivity extends ActionBarActivity{
//Do some stuff here
}
Every activity of my application extends this class.
Now here is my fragment:
...
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
...
public class MyFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Do some stuff...
((MyAbstractActivity)getActivity()).getSupportActionBar().setTitle(R.string.app_name);
}
//Do some stuff...
}
No error is shown in the editor.
But when I "Make" the project, I get this message in the "Event Log":
Compilation completed with 5 errors and 0 warnings in 4 sec
In the "Messages Make" part, I can see this for each time I try to cast "getActvity()" in "MyAbstractActivity":
java: inconvertible types
required: com.myapps.abstracts.MyAbstractActivity
found: android.support.v4.app.FragmentActivity
Well, I'm sad to say that, but I finally downloaded Eclipse, imported my project, and solved my problem, using the error messages of Eclipse.
It told me to "Fix Project Properties", I clicked, it did everything on his side, I tryed to launch the app, it worked.
Now that the problem is fixed, when I come back to Android Studio, it works too... But, for the moment, I think I'm gonna stay with Eclipse... Too much time lost for nothing. :(
Android Eclipse plugin gets flaky. Try to clean your project, then rebuild. Also, try restarting Eclipse. Also verify your project build path library order. Also, try to rebuild from the command line in the project with 'ant clean; ant debug', but do it while Eclipse is closed.

Unable to run Bitmap sample code for Android

I am trying to run the sample from :
http://developer.android.com/training/displaying-bitmaps/display-bitmap.html
However I encountered lots of errors like:
Description Resource Path Location Type
BuildConfig cannot be resolved to a variable ImageGridFragment.java /ImageGridActivity/src/com/example/android/bitmapfun/ui line 124 Java Problem
Description Resource Path Location Type
SuppressLint cannot be resolved to a type Utils.java /ImageGridActivity/src/com/example/android/bitmapfun/util line 99 Java Problem
I ran thru Google but could get nothing. Adjusted the android build target to 4.0.3 (15) but still no clue. Anyone ran this sample successfully?
Thanks.
Here is my solution:
1.Create a new class:
package com.example.android.bitmapfun;
public class BuildConfig {
public static final boolean DEBUG = true;
}
2.Comment the lines that contain "SuppressLint":
//import android.annotation.SuppressLint;
// #SuppressLint("NewApi")
Android developer tools r17 brings a feature to Eclipse where a class is auto built at build-time, called BuildConfig, which contains a constant that can be used by the app developer to sense whether the build is a dev build or a production build. This feature appears to be in the Eclipse integration support, so when using IntelliJ, this useful feature is not available
In gen folder with R.java there should be BuildConfig.java if your program compiled successfully.
/** Automatically generated file. DO NOT MODIFY */
package com.example.android.bitmapfun;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
Clean your project and try to launch it again.
It worked for me.
For me also it is not running directly import to eclipse. Just i put comments which lines is showing errors then it is working fine for me. May be it is not a right answer but we can see the application functionality by running the code so i did like that.

How to fix NoClassFoundError in android

I have two classes in a different projects.
I am importing the project that has the class that I need.
Now, I have no errors.
The project know's that class and I even made an object from that class, but when I'm trying to run it it crushes with the "NoClassFoundError".
How can i fix that?
import com.dmg.pixelservice.core.*;
import android.app.Activity;
import android.os.Bundle;
public class show extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Pixel pixel = new Pixel();
pixel.doIt(this,"fd7ccf36-3f85-11e1-8671-40409e0f44a1",true);
setContentView(R.layout.main);
}
}
When I debug, I can see that it crashes when I'm trying to do Pixel pixel = new Pixel();
Please help.
create new libs folder in your application .name must be same.and put your jar files in this folder.and
go to
java Build Path -> Configure Build Path -> Add jars
Looks like the jar file containing the Pixel class is not packaged into the APK.
To make that happen, it seems you need to copy the jar into the libs folder of your Android project.
See this question:
Approach for fixing NoClassDefFoundError?
Android Developer Guide:
http://developer.android.com/guide/developing/projects
it is easy to find the error if you send the src code of your Pixel class.

Categories

Resources