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.
Related
I am trying to give my Hbox a Border but in my project, it gives an error back. Don´t understand because in my friend's project it works perfectly.
`HBox hbox= new HBox();
hbox.setBorder(new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.SOLID, null, null)));
hbox.setSpacing(50);
hbox.setPadding(new Insets(20));
hbox.getChildren().add(imv);
hbox.getChildren().add(label);`
I found that if you import the wrong Color you will get the same error back:
//WRONG IMPORTS
import java.awt.Color;
//OR
import com.sun.prism.paint.Color;
The constructor BorderStroke(Color, BorderStrokeStyle, null, null) is undefined
This is easy to mess up because Eclipse will automatically recommend any of the 3 Color imports as options.
Remove the incorrect import for Color that you currently have, and instead make sure you manually import all the correct Classes at the top of your current Class so you do not use the wrong one:
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
Notice this is now javafx.scene.paint.Color instead.
I am using DailyMotion SDK in my android app to load the dailymotion videos in my app. The problem is when I play the video, Only audio is coming out but not video. Black screen is showing instead of video. Please help me this thanks in advance. My codes are
MainActivity.java
package com.example.rajeshkumarreddy.videoplayered;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import com.dailymotion.android.player.sdk.PlayerWebView;
import java.util.HashMap;
import java.util.Map;
public class DailyMotionActivity extends AppCompatActivity {
PlayerWebView playerWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerWebView=(PlayerWebView)findViewById(R.id.dm_player_web_view);
playerWebView.load("x1owz8e");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rajeshkumarreddy.videoplayered.MainActivity">
<com.dailymotion.android.player.sdk.PlayerWebView
android:id="#+id/dm_player_web_view"
android:layout_width="match_parent"
android:layout_height="215dp">
</com.dailymotion.android.player.sdk.PlayerWebView>
</RelativeLayout>
If you are using Android Studio's emulator, this can be the cause you are not seeing the video, only audio is perceived. Use your phone, there your video probably will show (if your code is correct). So don't use the emulator to test this. Best luck.
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
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 new to this platform, please help me to find what is the error...
setContentView(R.layout.main); // this line shows the error.
Code:
package com.example.helloandroid;
import android.R;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Try deleting the line import android.R then clean your project.
Just adding more details on why the error is coming.
As there is an import of android.R so setContentView() is looking for a layout file 'android.R.layout.main' and there is no main.xml in the layout files that come along with SDK. So, using the correct R.java import will work.
clean Project then try To Run because i faced same problem before a month and remember layout/main.xml must be their and it must not contains any error.
you can Also Do this
import android.R;
or
import your.application.packagename.R; Now Clear Project and Run it.
You must have to simply change the
setContentView(R.layout.main);
... to:
setContentView(R.layout.activity_main);
... because Layout contains this .xml file.
I hope your problem will be solved.
First remove import android.R;
After any change on xml fiels you must clean project.
Build > Clean Project
after that every things corrects.