A week ago, I was successfully using ListView, adding an item to it every time a button is clicked. Then I found I needed to put something in a thread separate from the main UI thread, and somewhere along the way, something broke.
Now I'm seeing an error every time I start Android Studio, saying FileNotFoundException: Entry fileTemplates//code/Google Test Fixture SetUp Method.cc.ft not found in E:/Programs/Android Studio/lib/idea.jar I go to that very folder though, and I can see that the file exists. This is the closest I've come to figuring out how to fix it.
I've also tried a cold reboot of both my computer and my phone, reinstalling Android Studio, creating a brand new project, and File > Invalidate Caches and Restart, none of which were helpful.
The only other answers I can find say it's because of being a 64 bit version on a 32 bit system. I am certain that's not the case, unless I somehow downloaded 64 bit while specifically looking for 32 bit.
I have no idea whether it's a problem with Android Studio, Gradle, something to do with the phone I'm using as a testing platform, or what.
I'm using:
Windows 8.1 Pro (32-bit)
2x Pentium 3.2 GHz (x64)
Android Studio 2.3.3
minimum SDK of API 15: Android 4.0.3 IceCreamSandwich
Java v1.8.0_144 (according to "java -version" in a command prompt)
Java 8 updates 60 and 144 are in my list of installed programs, along with Java SE Development Kit 8 updates 60 and 144
Here's the code from the fresh project that I mentioned:
MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ArrayList<String> listItems;
ArrayAdapter<String> adapter;
ListView listview = (ListView) findViewById(R.id.listview);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listItems = new ArrayList<>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
listview.setAdapter(adapter);
}
public void sendAnother(View view) {
adapter.add("button clicked");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="meh.myapplication.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Testing"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<ListView
android:id="#+id/listview"
android:layout_width="0dp"
android:layout_height="431dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/button"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
It turns out, all I was doing wrong was trying to initialize listview before onCreate(). Declaring it is fine, but initializing breaks it. I guess, despite being defined in the xml, View objects aren't instantiated until runtime?
I have a backup I had made from before anything broke, but it was also broken. Or, now that I'm messing with it again, partially broken. (button doesn't work, but I can output to the listview) I suppose I took this to mean something within Android Studio might have been broken. I think that's why I didn't notice the difference in where I tried to initialize listview.
I guess any rock will break if you hit it long enough with a hammer, eh?
Related
I'm trying to get a UDP stream from a GoPro camera.
https://github.com/KonradIT/GoProStream
I'm redoing this python code in android studio using vitamio.
But for some reason, as soon as I set the path, it crashes
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
But if I remove it, the app can launch but of course there is no video.
If someone encountered the same issue and found a solution, that would help me.
_myVideoView.setVideoPath("udp://#10.5.5.100:8554");
_myVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
_myVideoView.setBufferSize(2048);
_myVideoView.requestFocus();
_myVideoView.setMediaController(new MediaController(this));
_myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
_myVideoView.start();
I have done that for onCreate :
if(!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)){
return;
}
Vitamio.initialize(this);
the videoview :
<io.vov.vitamio.widget.VideoView
android:id="#+id/VideoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageButtonLeft"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/WebView"
tools:visibility="visible" />
and the build graddle :
implementation project(path: ':vitamio')
ps : I've tried to put the compile line in graddle, but it can't find the method compile and the implement line seem to work just fine.
ps2 : I just tried but even http link from YouTube doesn't work, I've definitely made a mistake but dunno where
Found the solution...
I was just importing the project but I didn't build it beforehand
So there was no way it could work.
But I gave up later for other reasons and I would recommend lib vlc instead of vitamio for displaying video from udp streams.
I've been making an android game and I noticed that it runs more than twice as slow on Nougat than on Marshmallow. In fact I figured out that between any two points in my code it seems to have roughly the same increase in time.
So I made a test application that, when the back button is pressed, does a test but I got roughly the same result again (code is below). I tested this using two android virtual devices(see the code for an average time in ms that was recorded) but I initially noticed it because my tablet got updated to nougat so it isn't AVD specific.
I'm stumped as to what is causing this. Some ideas I've had are the following:
The compiler isn't optimizated for nougat (api min is 15 and target is 25 and I'm building with sdk tools 25.0.2). Seems unlikely to me since it would be a pretty widespread issue that google would immediately fix.
The OS is using more resources and thus there are less left over for my game. Unlikely since this shouldn't account for a 2X decrease in speed.
The OS is added in a smaller limit for CPU usage. Maybe I have to request to be high priority or something alike however I'd expected clear documentation so also unlikely.
Android studio's settings for me aren't optimal. This one seems the most likely to me but I can't find anything that helps me yet.
Any insights or reproductions are appreciated! Thanks.
MainActivity
package com.example.nickgkg.test;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity{
TextView text;
long time = 0;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)this.findViewById(R.id.text);
}
#Override
public void onBackPressed(){
//API 24(nougat) vs API 23(marshmallow)
//API 25 performs the same as API 24 so I didn't include it
long t=System.nanoTime();
if(false){//Toggle this to change the test
float garbage;
for(int i=0;i<100000000;i++)
garbage=i*27/2200f;
//API 24:710ms vs API 23:620ms
}else{
for(int i=0;i<1000000;i++)
something();
//API 24:320ms vs API 23:120ms
}
time=System.nanoTime() - t;
text.setText(time/1000000f+"ms");
}
private void something(){
//BLANK function call
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.nickgkg.test.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/text"/>
</RelativeLayout>
Updating android studio fixed the problem
(updated from 2.2 to 2.3). I'm still not sure why this happened in the first place but I think it might have been that the debug builds for nougat weren't being optimized as much as the debug builds for marshmallow. On another note; perhaps if I tested with release builds instead of debug builds then I would never have got this issue (haven't tested this though).
OK, I'm tearing my hair out.
I have a simple default relative layout XML for my main activity, and defined a LinearLayout in the XML as well. In my Java code, I added a LinearLayout row, orientation horizontal, and added it to the XML Linearlayout (which I found by ID). When I then added Buttons or Textviews to that layour row, they showed up perfectly.
However, when I attempted to do the same thing in another activity, I can't get the TextViews or Buttons to show up at all. I originally had a background image and tried adding my Buttons and TextViews directly to the root RelativeLayout (foundById), with plans to move them around by .setX and .setY, but I took away the background and reverted to referencing a specific Linearlayout like my main Activity (for testing purposes, to remove any anomalies)and it still won't show them. I have re-arranged and tested forever and can not see what I'm missing.
Here's my current XML (stripped down for testing):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_open_template"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.mystuff.stupidapp.OpenTemplateActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/openTemplateMain">
</LinearLayout>
</RelativeLayout>
...and here's the current code (also stripped down):
public class OpenTemplateActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_template);
final Resources res = getResources();
Intent intent = getIntent();
String fileName = intent.getStringExtra(MainActivity.EXTRA_FILENAME);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels;
int screenWidth = displaymetrics.widthPixels;
LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
LinearLayout llMain = new LinearLayout(this);
llMain.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout llMainParent = (LinearLayout) findViewById(R.id.openTemplateMain);
llMainParent.addView(llMain);
Button bTest = new Button(this);
bTest.setText("TESTB");
llMain.addView(bTest);
//other code below unrelated.
}
}
Ideas, anyone? Please?
Answering my own question for those with a similar issue:
Turns out the APK was stuck, but only with code. Meaning any changes to the XML template (adding/removing Text or buttons or backgrounds) would reflect on the test device when I hit Play or Debug. But any changes to the code would NOT be reflected. I noticed this when I changed the tags in my debug logging and they were not reflected in the logs. I also noticed a Toast-like popup saying something about the app being dismissed manually and to re-run via IDE, but it didn't stay around long enough for a good look.
Clearing the cache and data, the uninstalling the app, then re-launching via the IDE play, fixed the issue. Code changes are now being reflected as expected, and code-created views are being shown as well.
You can prevent this or something similar from happening in the future by disabling the instant run feature in Android Studio: https://stackoverflow.com/a/35169716/3662251
Instant run basically incrementally compiles your code and only pushes the changes to the device. Unfortunately in its current state inconsistencies between code and runtime happen quite often and can lead to many wasted hours of bug hunting when that bug was actually introduced by instant run.
I'm developing an Android Wear app, and I have a ToggleButton named fitnessDebugToggle. It's defined in my manifests and can be referenced by findViewById. However, whenever I access it any other way my application crashes.
I'm currently debugging my app on a square Wear device ("Wear Square"), so the following manifest is for a square device.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:orientation="vertical"
tools:context="me.package.etc.MainActivity"
tools:deviceIds="wear_square">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView
android:id="#+id/fitnessDebugText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/fitnessDebugText"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ToggleButton
android:id="#+id/fitnessDebugToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textOff="#string/off"
android:textOn="#string/on"
android:layout_below="#+id/fitnessDebugText"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>
In my MainActivity class, I'm able to write the following:
public class MainActivity extends Activity {
ToggleButton fitnessDebugToggle;
MainActivity mainActivity;
public MainActivity() {
mainActivity = this;
}
#Override
public void onCreate(Bundle bundle) {
// Show view
super.onCreate(bundle);
setContentView(R.layout.layout_main);
// Setup
fitnessDebugToggle = (ToggleButton) findViewById(R.id.fitnessDebugToggle);
}
}
However right below the findViewById call, if I put
fitnessDebugToggle.setTransformationMethod(null);
it crashes with part of the stack trace being
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ToggleButton.setTransformationMethod(android.text.method.TransformationMethod)' on a null object reference
at the line I added the setTransformationMethod call.
I have looked at the question Android studio “ Attempt to invoke virtual method on a null object reference” however that deals with a NullPointerException on the findViewById call, not uponfurther calls. My package name has also been changed in this example.
Regarding comments:
If I comment out setTransformationMethod and add a setOnCheckedChangeListener call, it crashes as well with a similar stack trace.
Changing the ToggleButton's default state to false still produced a crash, same reason as before.
In my layout XMLs, changing the context to ".MainActivity" still crashed with the same reason as before.
you can use null only in one scenario like this try if else
if(checked){
button.setTransformationMethod(null);
}else {
button.setTransformationMethod(new PasswordTransformationMethod());
}
if you rename the xml file the try this option of android studio :
File -> Invalidate Catches/Restart
Then even problem occures the change ToggleButton id in xml and check is there java file gives error ? if yes then the id is perfectly integrated and updated in R.java.
Then change onCreate methos as :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
}
I have been following the instructions for the Android Bootcamp youtube series (3. Hello World) as closely as possible, but I have run into a whole slough of issues:
Problem 1: AVD Manager
Eclipse won't recognize my phone (Samsung Galaxy S5) for debugging/running apps. It doesn't show up in the AVD at all.
I have downloaded the driver required for my comp to communicate with the phone
I have enabled Developer's Mode on my phone
I have enabled debugging over USB
I have restarted Eclipse AND my phone
The phone is new, undamaged and runs just fine
My computer recognizes my phone and attributes the correct name, can extract files, etc
Problem 2: Running Apps
I attempted to circumvent the AVD Manager by clicking "Run" to simply select my phone. However, after electing to run as an "Android Application," I got an error:
Errors occurred during the build.
Errors running builder 'Android Pre Compiler' on project 'XXX'
I resolved this error by installing new software from (Help > Install new Software > http://download.eclipse.org/releases/luna > 'Collaboration' > 'Subversive SVN JDT Ignore Extensions' and 'Subversive SVN Team Provider') via the recommendation made on this thread. This made the error disappear.
Unfortunately, while the error no longer appears, the application still refuses to run. There are errors now in:
HelloWorld1 (ERRORS)
src (ERRORS)
com.example.helloworld1 (ERRORS)
HelloWorldActivity.java (ERRORS)
and
rec (ERRORS)
values (ERRORS)
values-v11 (ERRORS)
values-vw820dp (ERRORS)
Sadly, I don't know when the errors appeared, but I do know that they are preventing me from running anything.
I have attempted cleaning the project, but it fails every time and does not return a warning or message.
The only file I have touched since creating the project is the xml fragment. I click-and-dragged a couple elements in the Graphical Layout, then removed them. I have not touched any code, except the hex color code used to change the font color for "Hellow World" in the HelloWorldActivity. the hex color code is correct and works just fine.
Code for XML frag:
<RelativeLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.helloworld1.HelloWorldActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="102dp"
android:text="#string/hello_world" />
</RelativeLayout>
Code for HelloWorldActivity.java:
package com.example.helloworld1;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class HelloWorldActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hello_world, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have been dealing with nothing but errors for 4 days. I haven't gotten to do any actual work yet. I'm at wit's end.
Any and all help is deeply, deeply appreciated.
looks like a problem from your configuration
compare Project->Properties between your buggy project and the new one you created