Hello all, I've come across a very problematic issue/bug with ADB or Android Studio or both.
So I have my android phone connected via USB with USB Debugging enabled testing my app. I had added a few functions and wanted to test them (two problematic activities), so I went ahead and ran it. Upon clicking the navigation icon to start a new activity, the screen dimmed a bit, and after about 30 seconds, the entire screen was white with the exception of the native android dropdown menu at the top still visible.
I went ahead and tried to 'Stop' the app, at which point the android studio froze. By running a series of commands (as I later discovered) or by simply closing adb.exe
in the task manager, android studio resumed operation but disconnected from the device of course. My device however, had to do a full reboot as it seems the entire system was bogged down with some issue and would take 10x the usual time to open another app.
Upon retesting I noticed a few things
logcat
would print this over and over for about 30 times or moreCould not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
IO Error creating local socket at church.rmhymnal
java.io.IOException: Address already in use
at android.net.LocalSocketImpl.bindLocal(Native Method)
at ........
netstat -o -n -a | findstr 5037
in command prompt, I would see a massive list of TCP ports that had been apparantly opened repeatedly. (Some of those with TIME_WAIT would eventually be marked as ESTABLISHED I'm not sure what could be causing the issue but I'll drop the code for the activity I am calling, as well as the calling method below.
Calling function in Main Activity
Intent intent = new Intent(HomescreenActivity.this, IndexActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
startActivity(intent);
IndexActivity.java (Activity to be called)
public class IndexActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
DrawerLayout drawer;
LinearLayout ll;
NavigationView navigationView;
ArrayList<Song> songs;
int index;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view_index);
if (navigationView != null) {
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_index);
}
Intent intent = getIntent();
songs = Parcels.unwrap(intent.getParcelableExtra("songs"));
ll = (LinearLayout) findViewById(R.id.indexButtonView);
index = 0;
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
listIndex();
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.index, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
super.finish();
} else if (id == R.id.nav_hymns) {
Intent intent = new Intent(IndexActivity.this, SongDisplayActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
intent.putExtra("index", index);
startActivity(intent);
} else if (id == R.id.nav_index) {
//Do nothing
} else if (id == R.id.nav_settings) {
Intent intent = new Intent(IndexActivity.this, SettingsActivity.class);
startActivity(intent);
} else if (id == R.id.nav_about) {
//Unimplemented
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void listIndex() {
for (int i = 0; i < songs.size(); ++i)
{
if (!songs.get(i).getTitle().equals("")) {
final Button songButton = new Button(this);
songButton.setText(String.format("%s - %s", songs.get(i).getNumber(), songs.get(i).getTitle()));
songButton.setBackgroundResource(R.drawable.buttonshadowbg);
songButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
songButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
index = songButton.getText().charAt(0);
Intent intent = new Intent(IndexActivity.this, SongDisplayActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
intent.putExtra("index", index);
startActivity(intent);
}
});
songButton.setGravity(Gravity.CENTER_HORIZONTAL);
ll.addView(songButton);
}
}
}
}
All the methods before I created listIndex()
had worked perfectly. However after adding it as well as a few other methods in a different activity, it never worked since.
Any ideas leading to a possible solution would be highly appreciated, as my ability to develop and test is slowed greatly since I have to restart the testing device 9 times out of 10.
So at long last I have discovered a fix and a possible reason as to why this error even came up.
I began by disabling any additional code in my classes. I left it at default onCreate
etc. I also disabled the passing of the extras in my Homescreen Activity. I also had some findViewByID()
variable assignments which had multiple implementations for a few components. I fixed a few of them but not all.
Now here's the step that I believe actually fixed it. I have a class which reads from an included xml
file and adds data to an ArrayList
of a certain object Song
. Now because the xml
file holds quite a bit of records, I had inserted a sort of template to follow:
<songs>
<song>
<number></number>
<title></title>
<verse></verse>
<chorus></chorus>
</song>
<song>
<number></number>
<title></title>
<verse></verse>
<chorus></chorus>
</song>
<!-- etc -->
</songs>
Now as per the layout of the xml
file above, I had quite a few empty tags in there to be filled out at a later date (it's time consuming to put them all in at once). I'm no expert, but it seems that all the empty tags caused some sort of issue with the ArrayList
or the class Song
in some way.
Now all I did was to simply comment out the empty <song>
's that I had in the xml
tag, re-enable the methods that had been working before, and voila, no issue!
<songs>
<!--<song>
<number></number>
<title></title>
<verse></verse>
<chorus></chorus>
</song>
<song>
<number></number>
<title></title>
<verse></verse>
<chorus></chorus>
</song>-->
</songs>
I'm really unsure as to how exactly it worked, and I'd appreciate some sort of guidance on the issue, but perhaps the data fields that got empty values were coming up as null or something which eventually caused this kind of issue to happen. Anyway, crisis averted at last!
It is worth noting that Song
is parceable as well.