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.
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.
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.
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.
I'm trying to add ActionBar-PushToRefresh to my project. I've followed the instructions from Chris Banes Github there: Github ActionBar-PullToRefresh
Here is my view from which I want to enable the PullToRefresh feature:
<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ptr_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content, here we're using a ScrollView -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PULLTOREFRESH THE VIEW"
android:id="#+id/textView1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>
And here is my Activity to display the view:
package com.Test.pulltorefresh;
import android.app.Activity;
import android.os.Bundle;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.Options;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;
public class MainActivity extends Activity {
private PullToRefreshLayout mPullToRefreshLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Now find the PullToRefreshLayout to setup
mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
// Now setup the PullToRefreshLayout
ActionBarPullToRefresh.from(this)
// Mark All Children as pullable
.allChildrenArePullable()
// Set the OnRefreshListener
//.listener(this)
// Finally commit the setup to our PullToRefreshLayout
.setup(mPullToRefreshLayout);
}
}
When I launch my app, I got the blank view but nothing happens when I'm trying to PushToRefresh my view. Can someone show me how to fix it, I know that I've missed something. Thanks.
I may be a bit partial but...
you could consider using this
Maybe you have already achieved the functionality, but in the code above, you have commented out the line which defines the action on pulling the view.
//.listener(this)
You should uncomment this line and define the listener method, which should be called when the view is pulled.