0

Problem

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.

Testing

Upon retesting I noticed a few things

  1. My logcat would print this over and over for about 30 times or more

Could 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 ........

  1. Upon running the command 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 TCP ports

Code

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);
            }
        }
    }
}

Clarifications

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.

Final Thoughts

  1. Is it a problem related to my code or is it an issue with my adb or android studio?
  2. Could the issue be brought about by some error in another class that's not called in this particular method?

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.

4

1 回答 1

0

因此,终于我发现了一个解决方法以及为什么会出现此错误的可能原因。

方法

我首先在我的类中禁用任何附加代码。我将其保留为默认值onCreate等。我还在我的Homescreen Activity中禁用了附加功能的传递。我还有一些findViewByID()变量赋值,它们对一些组件有多种实现。我修复了其中的一些,但不是全部。

现在这是我认为实际上修复它的步骤。我有一个从包含xml文件中读取数据并将数据添加到ArrayList某个对象的类Song。现在因为该xml文件包含相当多的记录,所以我插入了一种模板以供遵循:

<songs>
    <song>
        <number></number>
        <title></title>
        <verse></verse>
        <chorus></chorus>
    </song>
    <song>
        <number></number>
        <title></title>
        <verse></verse>
        <chorus></chorus>
    </song>
    <!-- etc -->
</songs>

现在按照xml上面文件的布局,我有很多空标签要在以后填写(一次把它们都放进去很费时间)。我不是专家,但似乎所有的空标签都以某种方式导致了ArrayListor 类Song的某种问题。

解决方案

现在我所做的只是简单地注释掉<song>我在xml标签中的空的,重新启用以前工作的方法,瞧,没问题!

<songs>
    <!--<song>
        <number></number>
        <title></title>
        <verse></verse>
        <chorus></chorus>
    </song>
    <song>
        <number></number>
        <title></title>
        <verse></verse>
        <chorus></chorus>
    </song>-->
</songs>

我真的不确定它到底是如何工作的,我很感激关于这个问题的某种指导,但也许有空值的数据字段出现为 null 或最终导致此类问题发生的东西. 不管怎样,危机终于化解了!

值得注意的是,这Song也是可以解释的。

于 2016-04-17T02:29:21.133 回答