Full Code:
package restfulapiclient.tutecentral.com.restfulapiclient;
import android.app.ActionBar;
import restfulapiclient.tutecentral.com.restfulapiclient.R;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
......
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.create_user, menu);
return true;
}
.......
Error Code :
getMenuInflater().inflate(R.menu.create_user, menu);
Error Message :
Error:(150, 36) error: cannot find symbol variable menu
İnfo :
-Android Studio
-Example project
I know this post is some years old, but I was having the same problem and was unable to find the solution, so adding the steps that helped me resolve the issue to the thread just in case anyone else stumbles across this in future.
Solution: All you need to do is
click the option "Invalidate Cache/Restart..."
On the options menu that pops up, click "Invalidate and Restart"
And on restart of Android Studio, R.menu will become traceable.
Android Studio 3.6.3
try to remove menu.xml (inside res folder) errors then clean and build... it will work..
ProjectName\app\src\main\res\menu
follow above hierarchy and create create_user.xml file inside menu folder if menu folder in not there then create menu folder inside res.
If you won’t to create menu then create menu folder in res and then create create_user xml under menu folder.
res->menu->create_user.xml
create_user.xml like this
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:showAsAction="never"
android:title="#string/action_settings"/>
</menu>
Import Proper R Library:
import com.fha.blinkbook2022.R;
Like This My Error Resolve When we import proper library
Related
I am developing my first ever Android App using Eclipse.
I have the following code for my activity_main.xml view:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="biztalkers.gcmtest3.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/txtToken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</FrameLayout>
I have the following code within my MainActivity.java class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txtToken = (TextView) findViewById(R.id.txtToken);
My problem is with tha last line in the code block "final TextView txtToken = (TextView) findViewById(R.id.txtToken);", for this I get the error "txtToken cannot be resolved or is not a field". Can anyone see what I've done wrong?
Here are the imports
package biztalkers.gcmtest3;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import biztalkers.gcmtest3.R;
The line "import biztalkers.gcmtest3.R;" is underlined red as it "cannot be resolved"
Clean and re-build your project like this,
Project -> Clean -> Check your project and press OK.
Also verify your imports.. If you have import android.R delete it.. You should only import R with the package like import com.example.R
Retry by changing the id of the TextView with a new id and also clean and rebuild the project.
Simply save every files in your project.Because R.java will be modified at the time of saving.Now you may have a TextView in your layout.But , that will not be updated in the project....
Thanks to dcharms. The problem was due to an error in one of the res files
Check your import statements. Make sure you haven't imported the android R class (i.e. import android.R) instead of your own projects R class.
This question already has answers here:
R cannot be resolved - Android error
(108 answers)
Android - R cannot be resolved to a variable [duplicate]
(8 answers)
Closed 9 years ago.
i am new to android app development,
i have just created simple android project, but when it created it shows error.
"R cannot be resolved to a variable" when i press control shift +o
android.R is automatically added to my code but now it shows this error
"activity_main cannot be resolved or is not a field"
this is code of this project
package com.php.helloworld;
import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
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;
}
}
and when i tried to write this line
import com.php.helloworld.R
it shows "The import com.php.helloworld.R cannot be resolved"
There is also no problem in my xml file and and there is no file in gen folder
can somebody help me please to resolve this
Delete the import android.R. It actually refers to android resource within the android default library. If you want to use your resources you must import your R file not android's default library. Check if R.java is present in gen folder in the project.
I'm trying to implement a splash screen for my webview android app, so that it will display until the page is fully loaded. I was using the code from the accepted answer here but am running into some errors that I'm not sure how to solve. I assume that I'm missing a library of some sort, but I have no idea what.
The errors I'm getting are:
View cannot be resolved to a variable
error: Error: No resource found that matches the given name (at 'src' with value #drawable/vert_loading')
The code where I'm getting the view errors is:
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
findViewById(R.id.webview).setVisibility(View.VISIBLE);
}
});
While my layout xml file is:
<ImageView
android:id="#+id/imageLoading1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="visible"
android:src="#drawable/vert_loading"
/>
My assumption is that I might be missing an import of some sort, but I wouldn't know which one. The ones I have are:
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Any help would be greatly appreciated.
Add an drawable folder in your project res from File->New->Folder and put your drawable vert_loading in res->drawable folder. then Clean your project from Project->Clean.
I'm trying to just draw a simple image from the drawable-mdpi folder in android but I keep getting an error saying droid_1 cannot be resolved or is not a field, droid_1 is the name of the image, this is my code,
thanks for any help.
import android.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class GameView extends View {
private Bitmap bmp;
public GameView(Context context) {
super(context);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.droid_1);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bmp, 10, 10, null);
}
}
Change "import android.R;" to "import "import com.your.package.R;" where com.your.package is your package name...
You are importing android.R the android.R file won't contain your resources
You say that your image is in the drawable-mdpi folder. If you aren't using an MDPI display, Android won't be able to find an image to show on the screen. Make sure you have an image in each of the drawable-... folders, or a single image in the drawable folder, so that at least it will be able to find an image to use regardless of the screen resolution.
Also, you're trying to import the standard android.R package. Try removing this import line completely and let Eclipse suggest the correct R package to import - it'll be something like import com.yourapp.R;
package com.elfapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private Button btn_Login;
private EditText et_UserName;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn_Login = (Button) findViewById(R.id.button_login);
btn_Login.setOnClickListener(this);
et_UserName = (EditText) findViewById(R.id.editText_userName);
}
public void onClick(View v) {
if (v.equals(btn_Login)) {
// skriver ut en toast när man klickar på knappen
Toast.makeText(MainActivity.this, "Ansluter till server...", Toast.LENGTH_SHORT).show();
// används i debuggern för att påvisa att programmet exekverat hit
Log.v("ThisApp", "onClick Successful");
// TODO skickar det som står i et_UserName till controller (genom TCP/IP), som ska kolla om användaren finns
// send et_UserName.getText().toString() to controller
// if(username exists)
Intent intent = new Intent(this, RoomActivity.class);
this.startActivity(intent);
}
}
}
I'm getting an error on the line containing setContentView(R.layout.main);
Not sure about what the error/exception is because I'm not used to working in Eclipse..
This just happend to me a minute ago, but after researching a while, and read this post I notice this.
There is a custom R class with you app name, so when you try to import the missing class (in Eclipse, press Ctrl + Shift + O to import missing classes (Cmd + Shift + O on Mac)), you should see two posible classes the normal:
import android.R;
And a custom class with your project namespace:
import com.yourname.yourapp.R;
If you choose the custom class, problem solved!
Just take 2 steps and problem would be more likely to get solved:
Step 1:
Clean your project by clicking Project -> Clean.
Step 2:
Rebuild your project by clicking Project -> Build All.
Also make sure that your layout xml files are syntax error free and you don't have any image which has non-acceptable names (such as a "-" between image name).
Also I request you to have a look at problems window and let me know what errors are being shown there.
Using NetBeans 7.0:
If you fix imports before R.java has been generated for your project (before building it the first time) it will add the line:
import android.R;
which will override the local R.java that you are trying to reference.
Deleting that line resolved the errors for me.
Step 1 :
import android.*;
Step 2 :
clean your project
Step 3 :
Enjoy !!!
if you have multiple packages with different classes then it will be confusing: try this:
import package_name_from_AndroidManifest.R;
is this already solved?
i also had this problem. I solved it just by cleaning the project.
Project>Clean>Clean projects selected below>Check [your project's name]
This problem usually happen if eclipse accidentally compile the main.xml incorrectly.
The easiest solution is to delete R.java inside gen directory.
Once we delete, than eclipse will generate the new R.java base on the latest main.xml
Simply:
Right click on your project.
Go to properties.
Select android (second option in the Left panel).
Click "add..." (in library), select your project.
Click ok.
And finally, clean your project.
If this doesn't work, make sure that "android-support-v7-appcompat" is in your Project Explorer.
If it isn't there, you can add it by importing a simple project from: C:/android-sdks\extras\android\support\v7\appcompat
use code : setContentView(R.layout.activity_main); instead ofsetContentView(R.layout.main);