When ever I start a new project to practice using Android Studio the following
imports are added by default:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
As soon as I start adding another import to follow an example from a book or tutorial the whole new line disappears. If I add lines without the semicolon nothing happens. As soon as I begin adding the semicolons the new lines start disappearing. Why is this happening?
AndroidStudio auto "organizes" your imports. Just start adding your code and it will add the imports that you need. If you want to toggle this off, which I don't recommend, it's in: Preferences -> Editor(Under IDE Settings) -> General -> Auto Import
Related
I am using Spyder as Editor/IDE.
I play with the options to include files/function/modules form other olders just to get a better understanding of how it works.
But Spyder rearranges my import statements in alphabetical order and thus breaks my functionality:
This is what I need:
import sys
sys.path.insert(1,'d:/pathtohelloworld/')
import helloworld
But when I do "Save File" in Spyder, it rearranges to
import helloworld
import sys
sys.path.insert(1,'d:/pathtohelloworld/')
and of course it will fail, since it cannot import "helloworld" before the path is defined via sys.path.insert.
This alphabetical order might be a good python style, but how can I fix this issue ?
The old project name was expense_calculator.
Then I renamed the project to a different name, but somewere the old name still present, so when I import a package in Android Studio it substitutes the old name in imports, like
import 'dart:io';
import 'package:downloads_path_provider/downloads_path_provider.dart';
import 'package:expensecalculator/models/entry.dart';
import 'package:expensecalculator/models/entry_list_model.dart';
import 'package:flutter/material.dart';
...
How can I change all of the names throughout the whole project?
You have to change the package name parameter in the pubspec.yaml file to whatever new name you want. Then the imports will use the new name.
I am trying to start a project using PocketSphinx resources. What is the method for importing PocketSphinx resources into my Android Studio workspace?
import edu.cmu.pocketsphinx.Assets; //"unused import statement"
import edu.cmu.pocketsphinx.Hypothesis; //"unused import statement"
import edu.cmu.pocketsphinx.RecognitionListener; //"unused import statement"
import edu.cmu.pocketsphinx.SpeechRecognizer; //"unused import statement"
import edu.cmu.pocketsphinx.SpeechRecognizerSetup; //"unused import statement"
public class MainActivity extends AppCompatActivity implements RecognitionListener {...
As expected, I am getting a, "Cannot resolve symbol 'RecognitionListener' " on the last line. Thanks in advance.
The library is distributed as an Android Archive (AAR). Download from https://github.com/cmusphinx/pocketsphinx-android-demo/blob/master/aars/pocketsphinx-android-5prealpha-release.aar
Move pocketsphinx-android-5prealpha-release.aar into helloworld/app/lib/ directory.
In Android Studio go to File > New > New module, scroll down and choose Import .JAR/.AAR Package. Browse to /app/lib and select the .aar file. Click "Okay". Keep the apps module selected, click dependencies tab, click "+" on far right side, choose "Module Dependency". Select Module and click "Okay". For further information go to How to manually include external aar package using new Gradle Android Build System, scroll to Oliver Kranz's answer for nice screen grabs of the process.
When i write import such as import android.content.Intent; every time it is deleted automaticly. At the below of the ide unused import statement is existing. I have searched but solutions didn't work for me. How can i fix it ?
I am modifying a module which contains a class in it.
When I %run another module that uses the mofified class from IPython, the changes do not seem to take effect unless I restart IPython.
I have tried to use imp.reload, but this does not help. For example, I have put the following the code at the top of my module, but it does not appear to be using the updated version of my modified class (BigMySQLDatabaseGetter in the big_mysql_database_getter module)
import imp
import sys
from big_mysql_database_getter import BigMySQLDatabaseGetter
module_big_mysql_database_getter = sys.modules['big_mysql_database_getter']
imp.reload(module_big_mysql_database_getter)
Reloading a module doesn't automatically update all references that were created before, it just redefines everything within the module.
So if you do something like:
from spam import eggs
imp.reload(spam)
print(spam.eggs is eggs)
you'll get False, as eggs still references the old class. Likewise, instances created before the reload are instances of the old class, not of the new class:
import spam
e = spam.eggs()
imp.reload(spam)
print(isinstance(e, spam.eggs)) # False!
In your case, you can either reimport BigMySQLDatabaseGetter after reloading the module, or instead of directly importing the class just import the module and use big_mysql_database_getter.BigMySQLDatabaseGetter instead.