0

I am following the tutorial here along with somebody's help request here...

I am very new to Java/Android programming, and I'm not exactly sure how to 'launch' this section of code. In my AndroidManifest.xml I have it set as the first activity, assuming this would launch right when I started it:

    <activity
        android:name=".UploadImage"
        android:label="@string/title_activity_starting_point" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Unfortunately it doesn't work this way, because whenever I launch the app it automatically 'stops unexpectedly.' Any other Java class that I put right here launches fine, so I assumed it was something in the code. I'm just not sure where it needs to be for me to get the code 'running', as every time I compile it the program crashes on my phone.

LogCat says it is unable to resolve this line of code:

String image_str = Base64.encodeBase64String(byte_arr);
// old code was String image_str = Base64.encodeBytes(byte_arr), 
// but this didn't compile for me and a comment on another website 
// said that encodeBase64String could replace it...apparently not?
4
  • post your logcate trace! Commented Dec 7, 2012 at 8:00
  • what is the error you getting in the DDMS console? Commented Dec 7, 2012 at 8:01
  • <uses-permission android:name="android.permission.INTERNET"/> Commented Dec 7, 2012 at 8:02
  • Check this :stackoverflow.com/questions/12525725/… Commented Dec 7, 2012 at 8:05

2 Answers 2

1

Welcome to Android.

First off, locate your logCat in Eclipse. It'll be your best friend (and source of much frustration).

Secondly, once you find your logCat, you're likely going to see a NetworkOnMainThread exception. That means that you're attempting to execute a Network request on the main UI thread, which would cause the screen to "freeze" and stutter. It's a no-no, and as of Android 4.0, it will crash your app.

There is a way to explicitly override that, but it'd be better if you learned to avoid that to begin with -- no difficult at all. Just use an AsyncTask.

Lastly, be sure you have INTERNET permission in your Manifest.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I see it. It says it was unable to resolve the conversion from Base64 - this line of code: String image_str = Base64.encodeBase64String(byte_arr); The old code was String image_str =Base64.encodeBytes(byte_arr);, but this wouldn't compile and somebody commented that the aforementioned line fixed it for them. Apparently not for me. :/
Why don't you please edit your answer and add your code snipped, along with the relevant logcat. Hard to work out issues without context. And unless you're using "ancient" Android, brace yourself for the NetworkOnMainThread... ;)
0

Apparently the Base64 file I had entered got modified from the original one; the 'encodeBase64String' doesn't exist, and using:

int flag = 0;
String image_str = Base64.encodeToString(byte_arr, flag);

Fixed the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.