My activity is unable to resolve a symbol to the layout file - android

I have the following activity
package com.example.responsivelayout;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class DisplayText extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displaytext);
Intent intent = getIntent();
String message = intent.getStringExtra("com.example.responsivelayout.MESSAGE");
TextView tv = (TextView)findViewById(R.id.user_text);
tv.setText(message);
}
}
But the line setContentView(R.layout.activity_displaytext); gives error as "cannot resolve symbol". I have the following layout file as activity_displaytext.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
which is present in the layout/ folder. After trying all the efforts, i am clueless why i am getting this error. I tried project clean, make, eveything. Please help.

Make sure below import is not there
import android.R; //Resource class
It may be issue with import
Import should be
import com.example.responsivelayout.R;

Related

Flutter Image Picker not working due to plugins not automatically attaching to activity

I have added flutter in an existing Android app and I have been facing issues with Image picker library not working, showing the following error.
Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker_android)
According to the error I understand that it's due to GeneratedPluginRegistrant not being registered and I have to override configureFlutterEngine method. As I need to open the flutter module inside a fragment I cannot extend my activity using FlutterActivity because it does not support getSupportFragmentManager.
I tried extending my activity using FlutterFragmentActivity and was able to override configureFlutterEngine method but then faced the following error.
ava.lang.IllegalArgumentException: No view found for id 0x245a3c5c (unknown) for fragment FlutterFragment{647abea (0b17a247-4e8e-42bc-b5f3-6ab0796e458b) id=0x245a3c5c flutter_fragment}
Following are my MainActivity.java and activity_main.xml
MainActivity.java
package com.mch.testplugin;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.android.FlutterFragment;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends AppCompatActivity {
Context mContext;
FlutterFragment flutterFragment;
private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment";
FlutterEngine mFlutterEngine;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
flutterFragment = (FlutterFragment) getSupportFragmentManager()
.findFragmentByTag(TAG_FLUTTER_FRAGMENT);
// Create and attach a FlutterFragment if one does not exist.
if (flutterFragment == null) {
flutterFragment = FlutterFragment.createDefault();
flutterFragment = FlutterFragment.withNewEngine()
.initialRoute("/")
.build();
getSupportFragmentManager()
.beginTransaction()
.add(
R.id.frame_layout,
flutterFragment,
TAG_FLUTTER_FRAGMENT
)
.commit();
}
});
}
// #Override
// public void configureFlutterEngine(#NonNull FlutterEngine flutterEngine) {
//// super.configureFlutterEngine(flutterEngine);
// mFlutterEngine = flutterEngine;
// GeneratedPluginRegistrant.registerWith(new FlutterEngine(this));
// }
}
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">
<Button
android:id="#+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="200dp" />
</androidx.constraintlayout.widget.ConstraintLayout>'
Can someone please guide me the right way to do this? Your help is much appreciated.
The usual solution for similar problems is simply to stop the app and press the run button again

Android Studio creates blank layout xml file on create new resource xml file

I am developing my project in Android Studio. While creating ListView application, I am trying to create a new layout .xml file for list_item_row
What I did is right click on /res/layout then LayoutResourceFile then given the name.
But it generates a blank file.
Even the root node is not available, just a blank screen.
The same thing happening while creating new menu xml file.
What is the problem in the Android Studio and how can I rectify it?
Hope now my questions is clear.
In android studio, goto File -> Editor -> File and Code Templates and make sure you have something like
If you dont have this, may be you have to UPDATE/REINSTALL android studio.
In android studio, goto File -> Editor -> File and Code Templates ->other add the following codes...
In AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="">
<application android:icon="#drawable/icon">
</application>
</manifest>
In valueResourceFile.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
In resourceFile.xml
<?xml version="1.0" encoding="utf-8"?>
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android">
</${ROOT_TAG}>
In layoutResourceFile.xml
<?xml version="1.0" encoding="utf-8"?>
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="${LAYOUT_WIDTH}"
android:layout_height="${LAYOUT_HEIGHT}">
</${ROOT_TAG}>
In layoutResourceFile_vertical.xml
<?xml version="1.0" encoding="utf-8"?>
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="${LAYOUT_WIDTH}"
android:layout_height="${LAYOUT_HEIGHT}">
</${ROOT_TAG}>
In Activity.java
package ${PACKAGE_NAME};
import android.app.Activity;
import android.os.Bundle;
public class ${NAME} extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
In Fragment.java
package ${PACKAGE_NAME};
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ${NAME} extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return null;
}
}
In Application.java
package ${PACKAGE_NAME};
import android.app.Application;
public class ${NAME} extends Application {
}
In Service.java
package ${PACKAGE_NAME};
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class ${NAME} extends Service {
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
In Broadcast_Receiver.java
package ${PACKAGE_NAME};
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class ${NAME} extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
}
}
In Remote_Interface.aidl
package ${PACKAGE_NAME};
interface ${NAME} {
}
I hope this will help you...

Use Glide to Show Large Vector Drawable on Lollipop and above Devices

I'm able to use BumpTech Glide to show a large Vector Drawable on pre-lollipop devices but unable to do so on lollipop and above...The activity starts but the Imageview is not shown.
Here is the layout file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#FF5722"
tools:context=".Main.SplashScreen2.SplashScreen2">
<ImageView
android:id="#+id/imageViewSplashScreen2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/image_of_ahilya_ghat_river_bank_of_varanasi" />
</FrameLayout>
here is the java file
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.example.raviseth.searchviewtrials.Main.MainActivityListViewPage.activities.MainActivity;
import com.example.raviseth.searchviewtrials.R;
import uk.co.senab.photoview.PhotoViewAttacher;
public class SplashScreen2 extends AppCompatActivity {
FloatingActionButton fabSplashScreen2;
ImageView imageViewSpashScreen2;
PhotoViewAttacher photoViewAttacher = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashsreen2);
imageViewSpashScreen2 = (ImageView) findViewById(R.id.imageViewSplashScreen2);
if (imageViewSpashScreen2 != null) {
photoViewAttacher = new PhotoViewAttacher(imageViewSpashScreen2);
Glide.with(getApplicationContext())
.load(R.drawable.ghat)
.into(imageViewSpashScreen2);
photoViewAttacher.update();
}
}
}

List Crashes App when updated

I'm trying to get a ListView to show the contents of a simple array but my program crashes at the setAdapeter line. As I understand this is supposed to be because the final value comes out as null but I don't see why that would be the case or how to fix it. I have already tried using ArrayAdapeter instead as well as catching the null exception with a try block. The former changes nothing and the latter simply shows a blank activity with no list to speak of. Please help.
Here's Main Activity
package ballton.fowdeckbuilder;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnDecks = (Button) (findViewById(R.id.btnDecks));
Button btnCards = (Button) (findViewById(R.id.btnCards));
btnDecks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DeckCatalogue.class));
}
});
btnCards.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, CardCatalogue.class));
}
});
}
}
Here's the activity with the Problem
package ballton.fowdeckbuilder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class DeckCatalogue extends AppCompatActivity {
ListView Ldecks;
String TAG = "TAG";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_catalogue);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Ldecks = (ListView) (findViewById(R.id.DeckList));
String Decks[] = new String[] {"Faria","Melgis"};
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, Decks));
Ldecks.setAdapter(feed);
}
}
Here's the Layout for that activity
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="ballton.fowdeckbuilder.DeckCatalogue"
tools:showIn="#layout/activity_deck_catalogue">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/DeckList"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
And Here's the layout XML I use for the list times
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/Deck" />
</LinearLayout>
Use this code instead of yours:
ListAdapter feed = (new ArrayAdapter<String>(this, R.layout.show_deck, R.id.Deck, Decks));
This happened because you must supply the resource ID (as your xml: R.id.Deck) for the TextView you used for ListView.

Builder() says cannot resolve symbol on Gradle

I am trying to add an ad to my application and I get the error when I write this code :
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class isPrime extends Activity {
Button mButton = null;
TextView resultText = null;
EditText mInput = null;
RelativeLayout myLayout = null;
long input ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Look up the AdView as a resource and load a request.
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest;
adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
i.e the error I get is
Builder cannot be resolved into a Symbol
I have read through all the documentation(well at least I think I have.) I am totally new to this field. I would appreciate any help.
Also my XML code is :
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="blahblah"/>
You are using the wrong import for AdRequest looks like it is looking at the old admob implementation. Use --
import com.google.android.gms.ads.AdRequest;
instead of
import com.google.ads.AdRequest;

Categories

Resources