Good morning,
I have installed Eclipse and the plug in Android ADT.
I have created a new android project which is the classical :
package com.example.test_android_2;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
But when I run this code, there are the following things in the console window :
Invalid layout of java.lang.String at value
Error occurred during initialization of VM
Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class
There are no errors in the error window and nothing is happening. My connected device is not detected.
When i click on "Run as", there is no item (only "none applicable")
There is a problem of installation of Eclipse or ADT Android ?
Can you help me please ?
thanks
I faced this problem, and I think the best solutions as the following.
First, the versions that you want work with must be installed by SDK Manager.
Second,once you have installed the versions, then go to the run configuration and set the Android project that you have created. Third,
make sure that the SDK verison is the same as the target SDK as well as the Compile. From point of view if you are beginner with Android, I recommend you to start with API 14(version 4).
Thanks
Related
I am trying to build Android app everything worked fine but suddenly my Home Activity is throwing me an error not able to find symbol Menu and MenuItem. I am not sure what it went wrong. I rebuild the project and invalidate and cache the project but still its throwing me an error. Any help is highly appreciated.
import android.view.Menu;
import android.view.MenuItem;
Sample Code
import android.view.Menu;
import android.view.MenuItem;
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
You can try this.
Build-> Clean Project
Build-> Rebuild Project
I am just getting started towards android and i am having trouble with my hello world app, The problem is first it said R cannot resolved which i was able to overcome because there was no R.java files which i later copied from the internet
now there are three errors
1. activity_main cannot be resolved or is not a field
2. menu cannot be resolved or is not a field
3. action_settings cannot be resolved or is not a field
I have already tries control+shift+o,
already tried clean and build.
package my.hello;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}strong text
You should not create or modify R.java file manually as it's autogenerated by build system. Try to remove one copied from Internet and just rebuild your project with layout and menu files located in appropriated directories of the res folder
I'm trying to follow this tutorial from Google to create your own android app with Android Studio. But when I follow the 4th step on this page: http://developer.android.com/training/basics/firstapp/starting-activity.html Android Studio ends up with this error:
Cannot resolve symbol 'View'
This is what my code looks like at the moment:
public class MainActivity extends ActionBarActivity {
/** Called when the user clicks the Send button */
public void sendMessage(View view) { <--- (This line ends up with the error)
// Do something in response to button
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
What's wrong with this code? I'm not experienced in java and after looking at other questions I still couldn't find the right solution.
Thanks for helping!
I think you forget to include the import statement for View. Add the following import in your code
import android.view.View;
I am doing the same tutorial and ran into the same problem (that's why I found this question).
I see they explain this issue in the next paragraph named "Build an Intent":
Android Studio will display Cannot resolve symbol errors because this
code references classes that are not imported. You can solve some of
these with Android Studio's "import class" functionality by pressing
Alt + Enter (or Option + Return on Mac). Your imports should end up as
the following:
import android.content.Intent; import
android.support.v7.app.AppCompatActivity; import android.os.Bundle;
import android.view.View; import android.widget.EditText;
https://developer.android.com/training/basics/firstapp/starting-activity.html#BuildIntent
This problem can be resolved easily either by pressing alt + enter on the error to import android.view.View or by cross-checking that your method is outside protected void onCreate(Bundle savedInstanceState) and in the class parenthesis.
I've been having problems with Eclipse (Juno) when launching an application for android. I keep getting issues with the SDK not parsing and the application not launching. Any help would be greatly appreciated!!
Here is my code:
package com.example.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And here is my Console
[2014-09-09 11:43:47 - MyFirstApp] ------------------------------
[2014-09-09 11:43:47 - MyFirstApp] Android Launch!
[2014-09-09 11:43:47 - MyFirstApp] adb is running normally.
[2014-09-09 11:43:47 - MyFirstApp] Performing com.example.myfirstapp.MainActivity activity launch
[2014-09-09 11:43:47 - MyFirstApp] Error during launch: java.lang.NullPointerException
Any help would be greatly appreciated!!
I have faced this issue and solved it several times, with several different methods.
First of all, try close Eclipse and restart it.
If no good, try close Eclipse again and run /path/to/your/eclipse -clean, or you can do this in first step, instead of simply restarting it.
However, if it still cannot work well, maybe there's something wrong with AVD setting, check this.
I am new to android studio and I am reading the tutorials on i-programmer located here (http://www.i-programmer.info/programming/android/5914-android-adventures-activity-and-ui.html?start=2)
The two objects in the environment are a button and a large text widget instanced
in android studio's xml designer.
The problem: A method for setting text referenced in the tutorial is showing this error message when I try to run the code: error: cannot find symbol method setText(String)
And this error shows up in the text editor: Cannot resolve method 'setText(java.lang.String)'
Provided Source Code:
package com.example.helloworld1.helloworld1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onButtonClick(View v){
Button button=(Button) v;
v.setText("I've Been Clicked!"); // This is where the error happens
}
}
I think you meant to use button instead of v.
button.setText("I've Been Clicked!");