Observe very long String content in Eclipse - android

Since LogCat truncates long strings, I work around this using FileOutputStream to inspect the contents of very long strings.
It works but it forces me to 'adb pull' that file, which is not very convenient, compare to watching it on LogCat.
Is there any other way in Eclipse to watch very long strings?

For the record, the answer was found here.

when you stop in debug on the variable
do the following and past it to a text file

I think it will be easier to use the eclipse debugging view.
Set a break point at the line where you call Log.* and run your app in debug mode.
When execution reaches the break point the app will ... yes, it will halt.
In the Variables window you may now browse your data and display whatever you need. Copy and paste it at a safe place as well and don't forget to smile :)

What I do, is in "Variables->Change value".
That will show you a Windows with the full text. Then just Copy&paste to notepad.

try this:
public void logLargeString(String str) {
if(str.length() > 3000) {
Log.i(TAG, str.substring(0, 3000));
logLargeString(str.substring(3000));
} else
Log.i(TAG, str);
}
}

Related

Possible to auto fill code statements in android studio

I'm currently creating a soundboard app. I have about 100+ sound files to import.
I have code lines (android:onClick="song1") and (MediaPlayer mysound1).
Just wondering if there is a way to copy+paste these lines and have android studio auto change the line to "song2" and "song3" all the way to "song100"? Same goes for the "mysound1" all the way to "mysound100". I hope I do not have to do it manually :(
Thank you!
The approach you're using seems like a brute force method. There are much more elegant ways to approach this. For one, I would recommend creating dynamic Android components programmatically instead of in XML. Then you could hold all of your elements in a List or a Map, and you could tie them to a generic onClick listener. I'd recommend taking a look around online to figure out how to do some of these things.
But, if you would like to stick with you original method, I don't believe that Android has a way to auto number your click events. You could, however, write code to write your code. Here's a simple example using Java - since you're writing an Android app (utilizing the Eclipse console to print out to):
public class WriteMyCode {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= 100; i++) {
sb.append("<Button android:id=\"#+id/mybutton\"\n");
sb.append(" android:layout_width=\"wrap_content\"\n");
sb.append(" android:layout_height=\"wrap_content\"\n");
sb.append(" android:text=\"Click me!\"\n");
sb.append(" android:onClick=\"" + "song" + i + "\" />\n\n");
}
System.out.println(sb.toString());
}
}
You can then copy the output from the Eclipse console and paste it into your Android XML resource file.
I went to use Microsoft Excel to auto fill the numbers all the way to 100. Then CONCATENATE the ; to the end of "Mediaplayer mysound1".

SDL keeps failing to find font on Android

When I attempt to deploy my app using Eclipse it throws FileNotFoundException on my font, which I've now copied to both the assets/src and assets directory to be doubly sure.
I had this problem before, after succesfully integrating SDL_ttf into my Visual C++ build of the same app and transferring across to Eclipse for Android. Now I'm facing it again I thought I better write about it. The SDL_ttf source comes with a freetype folder already in place and referenced by android as external/freetype-2.4.12. DinoMage states I need to download this separately although he refers to freetype-2.4.11 being the latest. That's the only obvious difference from my VC build, apart from minor compiler intolerances.
I've got it working a bit now. I can sign the app (unsigned didn't work), disable USB debugging, and it will load the font and display a menu. From there it breaks, again, so I can't see how I'm supposed to debug it further. I'm sure I'll fix it somehow. But I'll also forget the obscura if I don't post here.
I don't know much about using the debugger with Android, but I can make suggestions otherwise.
Is your assets path really named "assetts"? If possible, I'm not sure how one would get Android and SDL to look there instead of "assets".
SDL and it's friend libs like SDL_ttf search for files local to the assets directory first and then search relative to the root directory. So I would expect that your "res/stubbornFont.ttf" will never load because it is in the resources "res" directory and SDL_ttf will not look there.
Maybe you can specify it relative to assets/, like "../res/stubbornFont.ttf", but I haven't tested that. It would work if you put the font in assets/ and loaded it as "stubbornFont.ttf".
I've think I've got closure on this.
It is possible to debug the app. By continuing it will trap several times trying to load one font. I think it stops eventually, I'm not sure. I've stepped through it from where it lands me at the throw stage. However single stepping from there begins from the synchronized statement, sorry it's Java but from my quick reference to What does 'synchronized' mean? I think this is a race condition
public final AssetFileDescriptor openFd(String fileName)
throws IOException {
synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
ParcelFileDescriptor pfd = openAssetFd(fileName, mOffsets);
if (pfd != null) {
return new AssetFileDescriptor(pfd, mOffsets[0], mOffsets[1]);
}
}
throw new FileNotFoundException("Asset file: " + fileName);//DEBUGGER traps here
}
You might be there all day single stepping that! It appears to perform all steps required of it and finally I land in:
public static ReadableByteChannel newChannel(InputStream inputStream) {
return new InputStreamChannel(inputStream);
}
No, not finally, lastly, there is
public static Context getContext() {
return mSingleton;
}
In the SDLActivity I extend.
That has a bunch of members I don't want to know about:
Luckily I discovered I can selectively "Disconnect" using a button in eclipse two along from debug/run. It has no keyboard shortcut and I'm not sure why but it will reconnect when I next trigger an exception. This is debugging as I know and love it in Android and Eclipse, still probably easier than GDB.
For arguments sake I've even replaced:
//TTF_Font *gFont = TTF_OpenFont( "res/stubbornFont.ttf", 160 );
with
TTF_Font *font=TTF_OpenFontRW(SDL_RWFromFile("res/stubbornFont.ttf", "rb"), 1, 160);//Same difference
UPDATE/EDIT
Here is the solution I was really looking for,
turning off uncaught exceptions in eclipse, it really is just that, Window->Preferences->Java->Debug and it's the very first box at the top for me.

Robotium for Android - solo.searchText () not working

I'm having a problem with searchText() function used with Robotium.
I'm searching for this string:
<string name="provisioning_wizard_title_2">Service Activation Wizard (Step 2)</string>
I defined it in string xml, and I'm searching it this way:
Activity act=solo.getCurrentActivity();
String string = solo.getString(act.getResources().getIdentifier("provisioning_wizard_title_2", "string", act.getPackageName()));
It fails when I call
assertTrue(solo.searchText(string));
and it fails also if i call:
assertTrue(solo.searchText("Service Activation Wizard (Step 2)"));
even if that is the string I'm seeing in the focused screen activity.
The strange thing is that it works if I use the same string without last character:
assertTrue(solo.searchText("Service Activation Wizard (Step 2"));
and it works if I use
assertTrue(solo.searchText(string.substring(0, string.length()-1)));
I hope someone could help me.
Sorry for my english!
Thank you.
PROBLEM SOLVED
I solved problem thanks to Renas Reda (Founder and maintainer of Robotium).
The problem is due to regex support in searchText(); some characters will trigger it.
Use Pattern.quote(string)
Example: Pattern.qoute("provisioning_wizard_title_2") and eveything works good!
I usually use Solo#waitForText(...) so I make sure I'm not losing some race condition.
Try this:
assertTrue(solo.waitForText( solo.getString(R.string. provisioning_wizard_title_2) );
Make sure you are importing the correct R.java file from your production project (not the test project).
I'm not sure, what string you are fetching. Try to log it:
Log.d("Debug", "String is: " + string);
you should rather call, here may be another issue related to package as activity may be in another package than main package of application:
String string = solo.getString(act.getResources().getIdentifier(act.getPackageName()+":string/provisioning_wizard_title_2"), null, null));
You can also get all visible texts, to make sure, what is on the screen:
for(TextView textView : solo.getCurrentViews(TextView.class)) {
Log.d("DEBUG", "Text on the screen: " + textView.getText().toString());
}

function is not working properly in Qt

I am making a simple GUI program to change bootanimation of a android phone but from last 4 days I am facing a problem and I don't know whats is reason, here is my code
void MainWindow::bootanim1()
{
QProcess rootboot;
QStringList path6,boottarget;
path6<<ui->lineEdit_6->text();
boottarget<<path6<<" /system/media";
ui->textBrowser->clear();
ui->textBrowser->setText("Remounting partitions...");
rootboot.start("bbin\\adb shell su -c \"busybox mount -o remount,rw /system\"");
rootboot.waitForFinished();
ui->textBrowser->setText("\nInstalling bootanimation.zip");
rootboot.start("bbin\\adb push ",boottarget);
rootboot.waitForFinished();
ui->textBrowser->setText("\nBootanimation has been changed! Try shutting down your phone to see new bootanimation");
}
This function is launched when a button is clicked but my problem is, this is not working! Secondly you can see in the code that to be more informative I have used a textBrowser to show user whats going on like Remounting partitions etc and the lineEdit_6 is the lineEdit widget where user will paste the path of the bootanimation.zip. So my problem is when I click the button only this is shown
Bootanimation has been changed! Try shutting down your phone to see new bootanimation
And everything above it I think is getting skipped, I don't know why? can anyone give me some hint on what I am missing?
Here you are mixing two different methods to give arguments to QProcess:
boottarget<<path6<<" /system/media";
rootboot.start("bbin\\adb push ",boottarget);
First method gives the program name and arguments in one QString.
Second method gives the arguments in a QStringList.
You are trying to give one argument ("push") in the program name string. It doesn't work, when the other arguments are given in a QStringList. The last argument also contains suspicious looking space in the beginning, although I don't know if it causes problems. Try this instead:
QStringList args;
args << "push" << path6 << "/system/media";
rootboot.start("bbin\\adb", args);
And path6 variable probably should be QString instead of QStringList.
Ui requires eventloop to refresh itself. When you do all changes in one function call, then only internal property change, and gui itself doesn't repaint. Use QCoreApplication::processEvents(); right after each ui->textBrowser->setText(...);

Android Debugging, how?

Ok so I've finally cobbled enough working parts into my app that its just plain old refusing to do anything now. I understand how to use logcat, but that is about it.
The main problem at the moment is that I get the error
Activity Idle Timeout for HistoryRecord then my package
I need to learn how to do better debugging. Plus if anyone can suggest things I should do for this error please let me know.
I think its something to do with the interactions with the database.
Cheers
EDIT:
What IDE are you using, if any?
Eclipse with Android tool has
moderately good debugging facilities;
set a breakpoint and debug away.
I am using Eclipse
And I know of breakpoints, but not their real use. Where would I set them for this error?
I am used to PHP where errors tell you a specific line to look at is there a way to do this in Eclipse?
In Eclipse if you right click in the margin next to your code - easy place to start is probably in your onCreate method - you can choose to Toggle Breakpoint. This will set a breakpoint at that location.
Now, in Eclipse choose Run->Debug As->Android Application.
This will run your app in the emulator and your app with stop running at your breakpoint. At this point you can step thru your code line by line using F6 I believe.
Once you've hit the breakpoint and your code is paused, use a guide like this http://www.ibm.com/developerworks/library/os-ecbug/ which will highlight all the different things you can do at that point.
Max... If you can wrap the offending line of code in try catch you can log the exception or set a breakpoint at the exception. So for the code below that will throw an exception:
String test= null;
try {
test.length();
}
catch (Exception e) {
Log.d(TAG,"test",e);
}
LogCat will display test,java.lang.NullPointerException blah, blah, blah
OR you can set a breakpoint at the Log.d line and if hit in DEBUG mode the app will pause and the variable window in the DEBUG view will show:
this:MyApp e:NullPointerException
BUT it does not sound like your app is throwing an exception, rather it is timing out on a database call. I would stub out the call to the database and see if the timeout goes away. Then slowly add back code until it times out.
JAL

Categories

Resources