Starting an app here:
http://developer.android.com/training/basics/firstapp/index.html
Copying directly from the tutorial and it’s full of errors. Even if I copy and paste. Is there a repository where I can view the working files and see if there’s anything wrong?
For example, in MainActivity.java:
package com.example.my.first.app;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
but it returns:
“View cannot be resolved to type” on line 10
“Multiple Markers at this line: Intent cannot be resolved to type” on line 11
“Multiple Markers at this line: EditText cannot be resolved to a type” on line 12
Then in DisplayMessageActivity.java:
package com.example.my.first.app;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
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(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);
}
}
and it returns:
“Intent cannot be resolved to type” on line 12
“Multiple Markers at this line: TextView cannot be resolved to a type” on line 16
This is my first app and I figured following the official tutorial would be alright but it’s not working. I’m using the latest Eclipse and Andorid SDK (downloaded tonight as a matter of fact.)
You have to import it.
On the left-side on eclipse there is an incon with a “X”, click on it and select “Import ‘XXXX'”.