I am following a tutorial on how to switch pages in flutter so I know that my code isn't necessarily wrong, however I keep getting an error with the way I am importing my classes. I have 2 pages and i'm not sure how to properly import them
The way the tutorial says to import it is: " import 'package:overflown/page2.dart'; "
but I get the error: Target of URI doesn't exist: 'package:overflown/page2.dart'. When I try to do it this way.
Any help would be great.
In package:overflown/page2.dart',
overflown is the name of your project you find in the pubspec.yaml
page2.dart is the path to the page named page2.dart.
have to modify the import path to that to your page path.
Example
You have a project with name testproject and a folder structure
lib
main.dart
page1.dart
The import should be
'package:testproject/page1.dart'
Related
I am new to Android Studio.
Right now, my android Studio project only has a single package, the application package. How do I create a subpackage ?
Currently, the package for the MainActivity.java is:
package com.davidgassner.plainolnotes.;
I want the directory for the subpackage to be: packagecom.davidgassner.plainolnotes.data;
When I created the subpackage using your's and Android Studio's instruction
I got the following:
package com.davidgassner.plainolnotes.com.davidgassner.plainolnotes.data;
I am getting an indication from Android Studio that the above path is not correct.
Right click in your main package -> New -> Package -> Give a name to your package and there you go.
If your main package is com.davidgassner.plainolnotes and you want to create com.davidgassner.plainolnotes.data , follow the steps above and when asked to input the package name, supply only "data". It will be created like this:
+ com.davidgassner.plainolnotes
+ data
In the top left corner you can switch your perspective from Android to Project to see all your project structure:
I have an error in my android code..my setContentView is not working.
my code is setContentView(R.layout.secondlayout);
Error is secondlayout cannot be resolved or it is not a feild.
Make sure that you placed the secondlayout.xml file inside res -> layout folder. Also make sure there is no error in this file. If the below line is there in your import statements, remove it.
import android.R;
Try this
import com.example.appname.R
Then, in eclipse go to project>clean , choose your project and press OK. Then wait until it is done. The clean operation regenrates R.
I haven't been able to find much on this topic.
I am trying to automate application testing, to where I place an app in a particular folder and I run the script: monkeyrunner.bat -v ALL myscript.py, and the script executes on whatever apk is in the folder called apkrepository. This makes it to where I do not have to alter my python script every time I test a new application.
The part where I am running into trouble is I am trying to use a variable for device1.installPackage()
See below for the code leading upto it.
installme = os.popen(r'dir C:\users\uname\desktop\apkrepository /A:-d /B').read()
print installme
# => com.application.android.apk #or whatever the package name is
filepath = r'C:\users\uname\desktop\apkrepository'
androidapp = filepath + '\\\' + installme
print androidapp
# => C:\users\uname\desktop\apkrepository\com.application.android.apk
#This exactly what I type below manually to get it to work
device1= MonkeyRunner.waitForConnection(15, "emulator-5554")
#Emulator was started in previous section of code, which is not shown here.
device1.installPackage(androidapp)
#DOES NOT WORK!!
device1.installPackage('c:\users\uname\desktop\apkrepository\com.application.android.apk')
#The only way it works seems to be to write the path in manually everytime.
I have tried many different ways to get this to work correctly, and I wasn't sure if it was something in the way(s) I was/were trying to do it. If the variable prints the correct file path I do not see how it would have issues working. This is probably something really easy, but this is where I am stuck. The error it gives:
E/Device: Error dyring Sync: Local Path does not exist. Error installing package C:\users\uname\desktop\apkrepository\com.application.android.apk
I am using windows 7 64 bit with python2.7 and the android sdk.
Thank you for any input/assistance provided! I have been stumped by this for a couple days.
Variables DO work for other places (monkeyrunner affiliated classes), like the device1.startActivity(component=runcomponent), where runcomponent is a combination of package + activity variables. Also note: I showed both device1.installPackages side by side for easy viewing. I do not run both in a row on my script.
I tried the same in linux machine, it works. Please have a look at the monkeyrunner script.
#! /usr/bin/env monkeyrunner
import re
import sys
import os
import java
import glob
import os
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device1= MonkeyRunner.waitForConnection(15, "emulator-5554")
mydir="/home/user/apk"
os.chdir(mydir)
for files in glob.glob("*.apk"):
print files
print "path " ,os.path.abspath(mydir+"/"+files)
device1.installPackage(mydir+"/"+files)
I am trying to validate an xml file against an xsd schema file using Xerces. I am hitting errors that I am unable to resolve, below is the logcat output. Please note that trying the same code and xercesImpl.jar file in a java application produces accurate validation results but moving the same to android results in errors. Please advice.
E/AndroidRuntime(792): java.lang.NoClassDefFoundError: org.apache.xerces.parsers.SAXParser
Thanks..
The solution is to use Apache Xerces ported to Android.
There is a project here
You have to do a svn chekout and export the proyect to a jar file to use as a library in your android proyect.
The code to instance SchemaFactory change a little.
I show you an example:
import mf.javax.xml.validation.Schema;
import mf.javax.xml.validation.SchemaFactory;
import mf.javax.xml.validation.Validator;
import mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory;
SchemaFactory factory = new XMLSchemaFactory();
Schema esquema = factory.newSchema(".../file.xsd");
The problem is that android doesn't have xerces and validating interface =)
But you can simply add validating from xerce:
You can use xerces and native schema validation (in java) in adnroid - you have to download xerces sources and (after some simple manipulations) include it to your own code - you will be able to use DocumentBuilderFactory.setShema method.
https://stackoverflow.com/questions/13142567/xml-schema-validation-xmlsignature-with-xerces-in-android
I'm getting R cannot be resolved error.
I read R cannot be resolved - Android error. But there android.R file.
My project compiles if .java files contain import com.companyname.productname.R statement.
If I change my productname in AndroidManifest.xml there's many errors saying package com.companyname.productname does not exist.
I tried to remove all import com.companyname.productname.R lines, but then I got package R does not exist errors on lines with R.*. How can I work around this? Thanks.
Update:
So answer is yes, I must import com.companyname.productname.R. I managed to compile project after changing productname in AndroidManifest and find-and-replace all import com.companyname.productname.R statements with new productname.
You custom R class is generated based on the package name in your AndroidManifest. So if you change it there, it will be newly generated with the new package name.
Therefore make sure that you import the correct one and remove all old imports.
If you R class is not generated, you should check the for XML errors in your resource files and/or your AndroidManifest. Fix the issues there and your R file should be generated again.