Gradle Error: cannot find symbol variable Settings_main - android

I currently have a problem changing the layout of my Android app. It doesn't work like usual.
When I want to change the layout to the settings layout with the press of a button, it gives the error: cannot find symbol variable Settings_main.
The code where this happens is
final ImageButton settings = findViewById(R.id.Settings_button);
settings.setOnCLickListener(new View.onClickListener() {
#Override
public void onClick(View v) {
setContentView(R.layout.Settings_main);
}
});
This is the error it's giving me
I have imported
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageButton;
Can someone please help me solve this?
Every name and Id does match according to IntelliJ as well, so I have no idea what could possibly be going wrong.

File-based resource names must contain only lowercase a-z,0-9 or underscore.
Please change file name Settings_main to settings_main

Related

Flutter Share_Plus_Web package not working anymore

Since quite some time now I am not able to solve this issue. Somehow the package in my flutter project 'package:share_plus_web/share_plus_web.dart' is underlined in red color. This is the code within the explorer:
// Generated file. Do not edit.
//
// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars
import 'package:cloud_firestore_web/cloud_firestore_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_storage_web/firebase_storage_web.dart';
import 'package:flutter_native_timezone/flutter_native_timezone_web.dart';
import 'package:share_plus_web/share_plus_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
FirebaseFirestoreWeb.registerWith(registrar);
FirebaseCoreWeb.registerWith(registrar);
FirebaseStorageWeb.registerWith(registrar);
FlutterNativeTimezonePlugin.registerWith(registrar);
SharePlusPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
And it says "Do not edit." So I'm not sure if I can just adjust things here in the code?
I also added a screenshot, hope that helps:
Thanks a lot in advance!

I'm unable to display image while running the app on Android Studio

I tried making an app in which after clicking on the button the image in the background changes to the image cat.png .
When I run the app, neither the image in the background comes up nor the the image which is supposed to show up in the place of the background image.
Please see the below code and help.
The onClick function for button is newCat.
package com.example.imagelesson;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
public void newCat(View view){
ImageView image = (ImageView)findViewById(R.id.catImgView);
image.setImageResource(R.drawable.cat);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Click on the search bar and search for onClick property then in onClick field add newCat and then run
It'll be mush easier to help you if you show us your xml file.
Anyway:
Firstly, I highly advise you to debug or add log to newCat method so you'll be sure that its being triggered properly.
Then:
Check out this: change-image-of-imageview-programmatically-in-android and that what-is-the-difference-between-imageview-setbackgroundresource-and-imageview-set
You have added the wrong field. If you take a look in your xml of the layout you should see the following line on the imageview:
tools:srcCompat="your image path"
This is set only when you design the layout. What you need to do is set the image in the previous box:
In XML it should look the following:
app:srcCompat="your image path"

Error from import android.R or from layout.main?

I keep either removing import.R or adding mypackage.R or deleting all imports and shift-control O
or deleting R.java.
I still get the error: main.xml cannot be resolved or alternately, R cannot be resolved to a variable. I have cleaned each time. How do you get this to work?
package com.hga;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Hga extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.activity_hga );
Yeah i used to run into those type of problems when i was starting programing for android. The R folder updates itself everytime code is written or saved and when a error occurs in your code for whatver reason it may be the R folder gives you that error report. At first clean but if that doesnt work as it usually wont you want to completely coment out your code /* .... */
then clean and the error should go way now you can pin point which bit of code is causing the error to occur in the R folder.
PS. this was my main source of frustration in coding android apps

How to solve this intent Error ?

I Wrote the Following code :
package com.aamir.cool;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView img = (ImageView)findViewById(R.id.facebook);
img.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://www.facebook.com/exandrok?ref=tn_tnmn"));
startActivity(intent);
}
});
}
}
I am getting error "Unknown Entity Intent" , "Unknown type of variable intent" .
How to Solve these Error ?
Add the following lines to your import statements:
import android.content.Intent;
import android.net.Uri;
Add the correct import statements
import android.content.Intent
import android.net.Uri;
If you're using Eclipse, you can add/organise/optimise your imports with the following shortcut
Cmd-shift-O on OSX
Ctrl+Shift+O on Windows / Linux
Rawkode Still Getting 2 Error : " Unknown entity 'uri" and "Unknown
member 'main of 'com.aamir.cool.R.id"
Please ensure that main.xml actually exists in your layout folder.
After importing the android.content.Intent; first check your xml files and be sure you dont have any layout problems and delete your R.java file and let it generate that again. after doing that right click to your project Android Projects -> Fix Project Properties then select "Project" and click "Clear" then try to run the code again. if still not working ctrl+a ctrl+x and ssave the file be sure you have no errors and ctrl+v again and try to run again.
Try verifying the AndriodManifest.xml in the main page which generates the package as seen in the gen/com folders

Missing Something Easy (Button OnClick Causing Null Pointer)

Suddenly my buttons cause null pointer exceptions. I have not changed any code in this activity class. I have been up most of the weekend trying to pin this down. I get null pointer exceptions in both the emulator and on device.
This is a simple screen with buttons. I could easily scrap this and write new code, but would like to know what has caused this issue. If not, I will just write new code.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button b1 = (Button) findViewById(R.id.MainActBtn);
b1.setOnClickListener(new View.OnClickListener() { //Error is here
public void onClick(View v) {
Intent intent = new Intent(StartScreen.this, MainActivity.class);
startActivity(intent);
}
});
Any help?
Try a fresh clean and build of your project. I got this error too in the past, caused by a changed R.class Resource class, but the static references in the using classes weren't properly replaced by the incremental java compiler, so the resources are no longer found.
I think You are not getting Null Pointer Exception because of the Button click just because of the declaration of the button..
You can check before writting the onClickListener..
if(b1==null)
Log.i("Null","Null");
The Problem is may be in setting the XML view or also check the button you are using is defined in the same xml you are using in setContentView.
After this all, also Clean and Build your project.

Categories

Resources