It says that "cannot resolve the symbol activity_sign_up" when I created a new empty activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
}
Added xml resource file code :
<androidx.constraintlayout.widget.ConstraintLayout 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=".SignUp">
Rebuild the project and check. If it didn't work just restart the Android studio. Happens for most of the people. Let me know if it worked or will try to help you out differently.
Related
I'm running:
package com.example.projectTest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class WelcomePage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome_page);
}
}
with:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".WelcomePage">
</androidx.constraintlayout.widget.ConstraintLayout>
but I'm getting the following error in the logcat when I run:
Could not get package user id: run-as: unknown package: com.example.projectTest
Could not find apks for this package: com.example.projectTest
Could not get package user id: run-as: unknown package: com.example.projectTest
Could not find apks for this package: com.example.projectTest
Failed to measure fs-verity, errno 1: /data/app/~~kWSycfQmCvKbfYx2KzxrNA==/com.example.projectTest-x4Zc9BUq0kRGdN5aX5AxXQ==/base.apk
The launch succeeds, but no app shows up on the emulator (Pixel 6 API 32). What could be the problem? Thank you.
I went to Run > Edit Configurations and set launch to a Specified Activity. I then set the specified activity and in AndroidMainfest.xml, inside the activity tag, I set exported=true. Now it works.
I create an app using binding and I get an error that I couldn't solve.
The error is
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newtest/com.example.mylibrary.MainActivity1}: java.lang.NullPointerException: Missing required view with ID: com.example.newtest:id/myRecyclerview
Thanks!
public class MainActivity1 extends AppCompatActivity {
RecyclerView.LayoutManager layoutManager;
ArrayList<POJOimage>pojoImageArrayList;
ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
layoutManager = new LinearLayoutManager(this);
binding.myRecyclerview.setLayoutManager(layoutManager);
init();
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity1"
android:background="#000"
android:padding="10dp">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myRecyclerview"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I strongly suspect some Android Studio bug.
I had the same bug, and everything I've had done was adding some TextView.
As it was easy to find this difference, I've just started fiddling with this TextView in xml. At some point bug disappeared.
And here comes the best. Before starting to deal with the problem I've saved problematic change with git. So at the end I've reapplied this change and ... everything worked. No more bug !
P.S. As this bug reappears, I've found that the easiest solution for getting rid of it is to use "Clean Project" from "Build" menu.
I'm an android novice. I'm trying to do some practice work but I am getting these two errors that I've tried for hours to fix
error: cannot find symbol variable activity_main
error: cannot find symbol variable tabLayout
Below is my MainActivity.java then after that the activity_main.xml
package com.example.rawtablayoutdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import android.R;
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
}
}
this is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
My screen that shows me the two errors
I'm sure you deep masters of code know the solution for my simple question born from a lack of understanding of Android Studio and making android apps. Please enlighten me.
Try deleting the import statement import android.R. Most probably it will work, if it doesn't try clearing and rebuilding the project from the Build -> Clean Project, then Build -> Rebuild Project.
This question already has an answer here:
android webview causing null pointer
(1 answer)
Closed 7 years ago.
I've reduced my application to an almost dumb state trying to figure out the issue. I'm using the AndroidStudio (IntelliJ version) for development. I've been developing just fine until just recently the application started crashing before launching it seemed. Logcat showed this:
NullPointerException: Attempt to invoke virtual method
'void android.webkit.WebView.loadUrl(java.lang.String)'
on a null object reference
As stated I've reduced the application to an almost pathetic state. (No services, No receivers), and here's my Activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
browser = (WebView) findViewById(R.id.web_view);
browser.loadUrl("file:///android_asset/www/index.html");
}
The line calling the error is the "browser.loadUrl" file, and this has been working fine for the last few hours. Please note that "requestWindowFeature" must be called above super.onCreate or the application will crash.
Here's my activity (Also unedited) and my application is nothing but a webview anyway.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
I'm a bit confused.
you missed setContentView(int layoutId). Without calling it your Activity has no widgets to look for, and findViewById returns null
You need to add setContentView() in onCreate() method for Activity.
After setting up content view, find reference of id will be get in Activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.<YOUR_LAYOUT_ID>);
browser = (WebView) findViewById(R.id.web_view);
browser.loadUrl("file:///android_asset/www/index.html");
}
The following classes could not be instantiated:
- com.amazon.device.ads.AdLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
java.lang.NoClassDefFoundError: Could not initialize class android.os.Environment
at com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:75)
at com.amazon.device.ads.InternalAdRegistration.<init>(InternalAdRegistration.java:52)
at com.amazon.device.ads.InternalAdRegistration.getInstance(InternalAdRegistration.java:64)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:185)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:176)
at com.amazon.device.ads.AdLayout.<init>(AdLayout.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
My main.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="top|center_horizontal" >
<com.amazon.device.ads.AdLayout
android:id="#+id/myAdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
My MainActivity.java is this
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
int defaultValue = R.drawable.blue;
int themedefault = ThemeChanger.THEME_BLUE;
appliedtheme = preferences.getInt("mytheme", themedefault);
ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
setContentView(R.layout.main);
AdRegistration.setAppKey("Application_Key");
this.adView = (AdLayout) findViewById(R.id.myAdView);
this.adView.loadAd(new AdTargetingOptions());
button1 = preferences.getInt("DigitButtonStyle", defaultValue);
buttonmadd = preferences.getInt("MemoryButtonStyle", defaultValue);
buttoncos = preferences.getInt("FunctionButtonStyle", defaultValue);
I had the same issue and followed Amazon developer guide. To solve this issue, just copy amazon library and paste it in your libs folder and than run.
It's a known issue in Eclipse ADT plugin, even if you use View.isInEditMode(), in some cases, it crashes in recent API versions (higher than 18). It's fixed in Android Studio.
If you want to see Layout Preview, you can try with different API version lower than 19.
Check the screenshot. It's using API 18. (Red box is Amazon AdLayout)