Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a little app I am trying to run on my phone as I build it, to see if things are going properly. The trouble starts in onCreate in MainActivity, which looks like this:
Java
public class MainActivity extends ListActivity {

    public static final String TAG = "MAIN";
    public static final String WEIGHTS_DIR = "/weights/input";
    // TODO Get this dir from app settings.

    // Keeps the filename whenever a user selects a file. Used when the user taps the 'Process' buttob.
    private String selectedFileName = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "Completed 'setContentView'.");

        String topDir = Environment.getExternalStorageDirectory().getAbsolutePath() + WEIGHTS_DIR;
        List<String> input_files = FileHelper.getInputFileNames(topDir);
        Log.i(TAG, getString(input_files.size()) + " input files found.");

//        ListAdapter listAdapter = new ArrayAdapter<>(this, R.layout.list_item, R.id.files_list, input_files);
//        setListAdapter(listAdapter);
//        final ListView listView = getListView();
//        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

Before I add the ListView code, now commented out, the app starts up on my device, and debugging works nicely, stopping at breakpoints, examining variables, etc.

As soon as I add that code, I get the following messages:
Connected to the target VM, address: 'localhost:8610', transport: 'socket'
Disconnected from the target VM, address: 'localhost:8610', transport: 'socket'

with "Disconnected" instantly after "Connected", where, when things were still nice, I would only get "Connected", and the main layout would display on the phone.

Then, on the phone, I clear the app's data and uninstall it, and comment out the ListView code, yet the debugging remains broken, with the instant "Disconnect" still there. I suspect some artefact in Android Studio's output is not being deleted when I rebuild, even after I do a clean. Once the debugging is broken like this, it also acts broken on an emulator for the phone, and a Nexus 9 emulator, so it really doesn't look device specific.

Worth noting is that if I do a Git reset on the branch I create before adding the ListView code, then debugging works again.

What I have tried:

I don't have much to try - I'm a complete Android Novice. If I copy all the code, minus the ListView stuff, into a new project, debugging works again. I have tried a breakpoint on the first line of the ListView stuff, so it doesn't execute until I want to, but the debugging still breaks as soon as I add that code. FileHelper is my own class, and getInputFileNames works fine and returns all files in the given directory.
Posted
Updated 6-Sep-16 19:15pm
v2
Comments
Richard MacCutchan 7-Sep-16 4:13am    
Chances are that there is a null reference or something similar in the commented out code, that usually crashes the app under testing. I would check the names of your resource items and make sure they are present in the final built application. Usually best to use findViewById to check them.
Darren_vms 7-Sep-16 6:08am    
Make setListAdapter(listAdapter); the last call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900