The android tutorial for "Build Your First App" (http://developer.android.com/training/basics/firstapp/index.html) is excellent, but they leave a couple of things out that I had to figure out for myself. I am developing on ubuntu linux and following the command line version of the tut. When I got to this part of the tut:
http://developer.android.com/training/basics/firstapp/running-app.html
I ran into the error "could not find javac" when I ran "ant debug".
I had to install javac like so ...
$ sudo apt-get install openjdk-6-jdk
The next problem was that I kept getting ...
error: device not found
- waiting for device -
red@ubuntu:~/android/workspace/MyFirstApp$ adb install bin/MyFirstApp-debug.apk
... I found out that I need to start the "server" like so ....
red@ubuntu:~/android/workspace/MyFirstApp$ adb kill-server
red@ubuntu:~/android/workspace/MyFirstApp$ adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
red@ubuntu:~/android/workspace/MyFirstApp$ adb install bin/MyFirstApp-debug.apk
100 KB/s (37439 bytes in 0.363s)
pkg: /data/local/tmp/MyFirstApp-debug.apk
Success
http://developer.android.com/training/basics/firstapp/running-app.html
I ran into the error "could not find javac" when I ran "ant debug".
I had to install javac like so ...
$ sudo apt-get install openjdk-6-jdk
The next problem was that I kept getting ...
error: device not found
- waiting for device -
... when I executed:
red@ubuntu:~/android/workspace/MyFirstApp$ adb install bin/MyFirstApp-debug.apk
... I found out that I need to start the "server" like so ....
red@ubuntu:~/android/workspace/MyFirstApp$ adb kill-server
red@ubuntu:~/android/workspace/MyFirstApp$ adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
red@ubuntu:~/android/workspace/MyFirstApp$ adb install bin/MyFirstApp-debug.apk
100 KB/s (37439 bytes in 0.363s)
pkg: /data/local/tmp/MyFirstApp-debug.apk
Success
Later on in the tut (http://developer.android.com/training/basics/firstapp/starting-activity.html)
ReplyDeleteThey forget to tell you add this line ...
Display Message
... to ...
~/android/workspace/MyFirstApp/res/values/strings.xml
If you do not do this you will get the error message ...
[aapt] /home/red/android/workspace/MyFirstApp/bin/AndroidManifest.xml:14: error: Error: No resource found that matches the given name (at 'label' with value '@string/title_activity_display_message').
... when you execute ...
ant debug
Dang ... I posted xml and forgot to escape the < chars
DeleteIf you are getting those ...
ReplyDelete[javac] Compiling 1 source file to /home/red/android/workspace/MyFirstApp/bin/classes
[javac] /home/red/android/workspace/MyFirstApp/src/com/example/myfirstapp/DisplayMessageActivity.java:9: cannot find symbol
[javac] symbol: class Activity
[javac] public class DisplayMessageActivity extends Activity {
[javac]
... error messages you need to have your java files look like this ...
red@ubuntu:~/android/workspace/MyFirstApp/src/com/example/myfirstapp$ cat MainActivity.java
package com.example.myfirstapp;
import android.app.Activity;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, com.example.myfirstapp.DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
red@ubuntu:~/android/workspace/MyFirstApp/src/com/example/myfirstapp$ cat DisplayMessageActivity.java
package com.example.myfirstapp;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import android.view.View;
import android.os.Bundle;
public class DisplayMessageActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(com.example.myfirstapp.MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
}
included all import statements as u mentioned and it worked like charm !!!
ReplyDelete