This is the tip eclipse shows in its layout editor
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
What does that mean? Here is the error in more detail
java.lang.NoClassDefFoundError: Could not initialize class android.os.Environment
at com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:78)
at com.amazon.device.ads.InternalAdRegistration.(InternalAdRegistration.java:58)
at com.amazon.device.ads.InternalAdRegistration.(InternalAdRegistration.java:54)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:203)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:183)
at com.amazon.device.ads.AdLayout.(AdLayout.java:127)
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)
I have tried to integrate the ads using both code and xml but nothing works?
Here is my xml
<?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="match_parent"
android:layout_height="wrap_content" />
I am using amazon-ads-5.1.153.jar from their sdk. Here is my main.java
#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);
AdLayout adView;
ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
setContentView(R.layout.main);
AdRegistration.setAppKey("AppKey");
adView = new AdLayout(this);
adView.loadAd(new AdTargetingOptions());
AdRegistration.enableTesting(true);
AdRegistration.enableLogging(true);
AdTargetingOptions adOptions = new AdTargetingOptions();
adView.loadAd(adOptions);
Has anyone faced this problem. Any help would be appreciated.
You may instiate ad in java code as
private static final String APP_KEY = "your app key";
private static final String LOG_TAG = "adsample";
AdLayout ad;
ViewGroup adcon;
this.adcon = (FrameLayout) findViewById(R.id.root_layout);
AdRegistration.enableLogging(true);
// For debugging purposes flag all ad requests as tests, but set to false for production builds.
AdRegistration.enableTesting(true);
try {
AdRegistration.setAppKey(APP_KEY);
} catch (final IllegalArgumentException e) {
Log.e(LOG_TAG, "IllegalArgumentException thrown: " + e.toString());
return;
}
ad = new AdLayout(this,AdSize.SIZE_300x250);
LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
ad.setLayoutParams(layoutParams);
ad.loadAd();
adcon.addView(ad);
This will really works
Related
It's been days of researching and I cannot figure out a way to do it.
Here is the link of the library on Github. Library
public class PDFViewActivity1 extends AppCompatActivity {
LinearLayout root;
EditText etPdfUrl;
Button btnDownload;
PDFPagerAdapter adapter;
String id;
ArrayList<String> topicLink;
File file;
String filePath;
PDFViewPager pdfViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_p_d_f_view);
root = (LinearLayout) findViewById(R.id.remote_pdf_root);
final Context ctx = this;
Intent intent = getIntent();
String str = intent.getStringExtra("filePath");
str = str; // This contains the path of the PDF on my device
Log.i("filePathInString", str);
pdfViewPager = new PDFViewPager(ctx, str);
pdfViewPager.setId(R.id.pdfViewPager);
pdfViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
adapter = new PDFPagerAdapter(ctx, str);
pdfViewPager.setAdapter(adapter);
root.removeAllViewsInLayout();
root.addView(pdfViewPager,
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
}
#Override
protected void onDestroy() {
super.onDestroy();
((PDFPagerAdapter) pdfViewPager.getAdapter()).close();
}
}
The PDF renders perfectly form my device but I cannot see the page numbers, title , total pages of the PDF when the PDF is loaded.
This is my XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/remote_pdf_root"
android:orientation="vertical"
android:background="#FFFFFF"
tools:context=".PDFViewActivity1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<es.voghdev.pdfviewpager.library.PDFViewPager
android:id="#+id/pdfViewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
What do I do when the page is scrolled, I cannot figure out a thing , I tried a lot of methods of the PDFAdapter but I an unsuccessful :( How can I do the task ?
RelativeLayout remotePdfRoot = findViewById(R.id.remote_pdf_root);
remotePDFViewPager = new RemotePDFViewPager(this, downloadFileUrlConnection, url, listener);
remotePDFViewPager.setId(R.id.pdfViewPager);
//after file loading success
PDFPagerAdapter adapter = new PDFPagerAdapter(this, FileUtil.extractFileNameFromURL(url));
remotePDFViewPager.setAdapter(adapter);
updateLayout();
private void updateLayout() {
remotePdfRoot.removeAllViewsInLayout();
remotePdfRoot.addView(remotePDFViewPager, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
}
I preview pdf this way and there will be a pagenumber.
You can use https://github.com/barteksc/AndroidPdfViewer library for this and you can get the page count by
`vpPdf.fromAsset("sample.pdf").onError {
Log.i(TAG, "${it.localizedMessage}")
it.printStackTrace()
}.onPageError { _, t ->
t.printStackTrace()
}.enableSwipe(true).swipeHorizontal(true).onPageChange { page, pageCount ->
//here page count is count of page user currently is viewing.
}.load()`
I had to use this lib at work and it is working perfectly fine!!
The above code is from kotlin but you can convert it to java i guess,If you are not able to convert it the kindly comment so i will help you with that too!!.
I can't find out how to use camerax with previewview.
Here is an example of how to use Camerax with PreviewView, the code uses the latest versions of CameraX, meaning camera-camera2 version 1.1.0-beta01, and camera-view version 1.1.0-beta01.
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
previewView = view.findViewById(R.id.preview_view);
setCameraProviderListener();
}
private void setCameraProviderListener() {
ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
ProcessCameraProvider.getInstance(requireContext());
cameraProviderFuture.addListener(() -> {
try {
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
bindPreview(cameraProvider);
} catch (ExecutionException | InterruptedException e) {
// No errors need to be handled for this Future
// This should never be reached
e.printStackTrace();
}
}, ContextCompat.getMainExecutor(requireContext()));
}
private void bindPreview(ProcessCameraProvider cameraProvider) {
imageAnalyser();
imageCapture();
CameraSelector cameraSelector =
new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
Preview preview = new Preview.Builder().build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
ViewPort viewPort = previewView.getViewPort();
if (viewPort != null) {
UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(imageAnalyzer)
.addUseCase(imageCapture)
.setViewPort(viewPort)
.build();
cameraProvider.unbindAll();
Camera camera = cameraProvider.bindToLifecycle(this, cameraSelector, useCaseGroup);
CameraControl cameraControl = camera.getCameraControl();
cameraControl.setLinearZoom((float)0.3);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.camera.view.PreviewView
android:id="#+id/preview_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/Yellow"
android:layout_gravity="center" />
</LinearLayout>
Here is an article that explains PreviewView and how to use it. It's valid up to version 1.0.0-alpha10 of camera-view, I'll try to keep it up to date.
I had set android:hardwareAccelerated="false" while debugging a different error, and had forgotten to remove it (or set it to true). I quickly noticed camera functionality had stopped working.
Make sure there is no android:hardwareAccelerated="false" in your apps manifest. If there is, either remove it, or set it to true. If this is set to false it will affect the camera preview stream.
TL;DR
Remove any android:hardwareAccelerated="false" in your manifest, or set it true.
I'm using Android Studio and trying to show some chosen Street View paths in VR. I already have Street View running well and now I'm trying to show it in VR.
I have put the com.google.vr.sdk.widgets.pano.VrPanoramaView in the layout and, inside onCreate in my class, referenced it to a VrPanoramaView variable through findViewById. Now I'm trying to show an image calling a method which I've defined in this class, loadPanoImage. This method loads an image from the storage and shows it through loadImageFromBitmap.
The problem is that it isn't able to show anything, even though I've followed a guide and I've done everything as showed. I've even tryed calling it in different parts of the code (before doing any other action, on clicking a button, before and after showing streetview) but I can't understand why it isn't working and how will I be able to use it to show images taken from StreetView (I don't know if I will be able to do it dinamically or I should download them and put them in the storage).
I'm putting part of the code for reference:
public class VrExperience extends FragmentActivity {
Button buttonCitta;
Button buttonMare;
Button buttonMontagna;
TextView titleTextView;
// George St, Sydney
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
// LatLng with no panorama
private static final LatLng INVALID = new LatLng(-45.125783, 151.276417);
//VrPanoramaView is inserted in the layout
private VrPanoramaView panoWidgetView;
//StreetViewPanorama is another class in my project which shows Street View
private StreetViewPanorama mStreetViewPanorama;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vrexperiences);
panoWidgetView = (VrPanoramaView) findViewById(R.id.pano_view);
panoWidgetView.setEventListener(new VrPanoramaEventListener());
//download image and show it, but it doesn't show anything
loadPanoImage();
titleTextView = (TextView) findViewById(R.id.titleTextView);
buttonCitta = (Button) findViewById(R.id.buttonCitta);
buttonCitta.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!checkReady()) {
return;
}
titleTextView.setVisibility(View.GONE);
buttonCitta.setVisibility(View.GONE);
buttonMare.setVisibility(View.GONE);
buttonMontagna.setVisibility(View.GONE);
loadPanoImage(); //it doesn't show anything
mStreetViewPanorama.setPosition(SYDNEY);
loadPanoImage(); //it doesn't show anything
}
}};
//code for buttonMontagna and buttonMare as well, it's identical
SupportStreetViewPanoramaFragment streetViewPanoramaFragment =
(SupportStreetViewPanoramaFragment)
getSupportFragmentManager().findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(
new OnStreetViewPanoramaReadyCallback() {
#Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
mStreetViewPanorama = panorama;
// Only set the panorama to INVALID on startup (when no panoramas have been
// loaded which is when the savedInstanceState is null).
if (savedInstanceState == null) {
mStreetViewPanorama.setPosition(INVALID);
}
}
});
}
/**
* When the panorama is not ready the PanoramaView cannot be used. This should be called on
* all entry points that call methods on the Panorama API.
*/
private boolean checkReady() {
if (mStreetViewPanorama == null)
return false;
return true;
}
/**
* Called when the Animate To Invalid button is clicked.
*/
public void onGoToInvalid(View view) {
if (!checkReady()) {
return;
}
mStreetViewPanorama.setPosition(INVALID);
}
//retrieves image from the assets folder and loads it into the VrPanoramaView
private void loadPanoImage() {
VrPanoramaView.Options options = new VrPanoramaView.Options();
InputStream inputStream = null;
AssetManager assetManager = getAssets();
try {
inputStream = assetManager.open("demo2.jpg");
options.inputType = VrPanoramaView.Options.TYPE_MONO;
panoWidgetView.loadImageFromBitmap(
BitmapFactory.decodeStream(inputStream), options
);
inputStream.close();
} catch (IOException e) {
Log.e("Fail", "Exception in loadPanoImage" + e.getMessage());
}
}
#Override
protected void onPause() {
panoWidgetView.pauseRendering();
super.onPause();
}
#Override
protected void onResume() {
super.onResume();
panoWidgetView.resumeRendering();
}
#Override
protected void onDestroy() {
panoWidgetView.shutdown();
super.onDestroy();
}
}
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/vrExperienceActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.vr.sdk.widgets.pano.VrPanoramaView
android:id="#+id/pano_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_weight="5"
android:scrollbars="none" />
<TextView
android:id="#+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:text="VR Experience"
android:textAlignment="center"
android:textAppearance="#android:style/TextAppearance.Large"
android:textColor="#0000F0"
android:visibility="visible" />
<Button
android:id="#+id/buttonCitta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Città" />
<fragment
class="com.google.android.gms.maps.SupportStreetViewPanoramaFragment"
android:id="#+id/streetviewpanorama"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: #LucioB
a) those are the places I've tried to call loadPanoImage, but neither of them showed anything. It acts as nothing happens calling that method, the program keeps going to the other tasks. I'd like for images to be shown directly in VR when a button is clicked, or if that isn't possible to add the classic cardboard button in Street View mode to pass to VR view.
b) I mean the code isn't doing what I expected it to do. I thought that once I created VrPanoramaView in the layout and used it to show an image through .loadImageFromBitmap it would have shown the image I loaded from asset (I have an image saved on the virtual SD), and that once I was able to do that for a single image I would have found a way to do it for a whole path.
The code doesn't give any exception, I think I'm making a logic mistake or I didn't understand how VR api work.
EDIT: I've found that the java code is working, the problem was in the layout which didn't permit to see VrPanoramaView because it was obscured by StreetViewPanorama
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
I'd like to create a TextView with the name of the person you've just tapped, but when I tap a name, it prints an error message to the console.
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView parentView, View childView, int position, long id) {
System.err.println("clicked " + position);
System.err.println("clicked " + friendsIO.getPresentationText(position));
try {
JSONObject friendInformations = new JSONObject(friendsIO.getPresentationText(position));
String friendNames = friendInformations.getString("name");
System.err.println(friendNames);
TextView peopleName = (TextView) findViewById(R.id.peoplePerson);
peopleName.setText(friendNames);
String friendEmails = friendInformations.getString("email");
System.err.println(friendEmails);
String friendNumbers = friendInformations.getString("phone number");
System.err.println(friendNumbers);
String friendEmailsNumbers = friendNames + "\n" + friendEmails;
// TextView peopleInformations = (TextView) findViewById(R.id.peopleInfo);
// peopleInformations.setText(friendEmailsNumbers);
} catch (Exception e) {
e.printStackTrace();
}
final LayoutInflater peopleInflater = LayoutInflater.from(MainActivity.this);
final View peopleView = peopleInflater.inflate(R.layout.popup2, null);
final PopupWindow peoplePopup = new PopupWindow(peopleView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
peoplePopup.showAtLocation(peopleView, Gravity.CENTER, 0, 0);
final Button peopleBack = (Button) peopleView.findViewById(R.id.cancel_button);
peopleBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
peoplePopup.dismiss();
}
}
);
I print the name to the console first, to make sure that it actually exists and I get the name I tapped (as well as the email and number, obviously), but instead of printing the name to the screen in a TextView, it gives me the following error message:
10-01 17:39:55.505 4259-4259/com.logit.data.returntosender W/System.err﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
10-01 17:39:55.506 4259-4259/com.logit.data.returntosender W/System.err﹕ at com.logit.data.returntosender.MainActivity$1.onItemClick(MainActivity.java:60)
It says the error is at the line
System.err.println(friendNames);
But the TextView is only actually given afterwards, in line 61. I have tried around a bit, and not found what the problem could be. It's technically exactly how it should be, at least that's what I've been able to gather from other StackOverflow questions and a thorough google search.
The XML file of the popup with the name (and email and phone number, but that's not part of the question):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#color/colorAroundPopups"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal">
<TextView android:id="#+id/peoplePerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorOfPopups"
android:textStyle="bold"
android:text=""
android:textSize="52sp"/>
<TextView android:id="#+id/peopleInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorOfPopups"
android:textStyle="normal"
android:textSize="26sp"/>
<Button android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cancel_it" />
</LinearLayout>
Thanks in advance
-Léon
EDIT: I added the part of the code where the popup, containing the TextView, is created.
EDIT: I found the found the solution. I had to put the name of the view containing the TextView before findViewById
Also, Frank N. Stein, thank you for not helping at all by sending me a question I had already looked through :)
You are retrieving the view from the activity, if the TextView was on the list item view, you would change...
TextView peopleName = (TextView) findViewById(R.id.peoplePerson);
to...
TextView peopleName = (TextView) childView.findViewById(R.id.peoplePerson);
instead of doing this:
TextView peopleName = (TextView) findViewById(R.id.peoplePerson);
do this:
TextView peopleName = (TextView) childView.findViewById(R.id.peoplePerson);
as your textview is a child of the listview.
[Hello], I have a problem.
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="num_e1_n1">%1$d</string>
</resources>
In the layout file :
<TextView
android:id="#+id/num_joueur_e1_n1"
style="#style/num_joueur"
android:layout_alignTop="#id/maillot_rouge1"
android:layout_centerHorizontal="true"
android:text="#string/num_e1_n1" />
And in the method onCreate() in the .java file :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saisie_stats);
// ...
Resources res = getResources();
String numero = String.format(res.getString(R.string.num_e1_n1), 98);
num_rouge1 = (TextView) findViewById(R.id.num_joueur_e1_n1);
num_rouge1.setText(numero);
num_rouge2 = (TextView) findViewById(R.id.num_joueur_e1_n2);
num_rouge3 = (TextView) findViewById(R.id.num_joueur_e1_n3);
num_rouge4 = (TextView) findViewById(R.id.num_joueur_e1_n4);
//***
}
Unfortunately when I run my application, my Textview displays "%1$d"
Except I want it displays 98.
What's wrong? What do I need to change?
Thank you very much.
Update:
The problem seems to be that you somehow don't succeed to set text programmatically and your TextView shows value declared in layout :
<TextView
...
android:text="#string/num_e1_n1" />
You can try putting another string in layout to confirm that. Then you have to figure out why your num_rouge1.setText() code is not run.
You could try String.format, like this :
String numero = String.format(res.getString(R.string.num_e1_n1), 98);
But it should behave identically to your existing code.
Hope that helps.