我在Android Studio中制作了一个应用程序,可以让你跟踪你曾经乘坐过山车的次数,并计算出你经历了多少次力量等等.
我希望rideCount变量在退出时保存,所以我让它写入文件.然后,当该活动开始时,它将读取该文件并将其放入rideCount变量中.因为它在退出时写入,所以文件中没有任何内容.
我想要它做这种情况发生时被设置rideCount到0,并调出设置一切了方法,但我似乎无法在传递rideCount变量来捕捉位.有人可以帮忙吗?
预先感谢.
File file = new File("AltonAirCount.txt");
try{
Scanner input = new Scanner(file);
int rideCountFile = input.nextInt();
final int[] rideCount = {rideCountFile};
onCreate2(rideCount);
} catch (FileNotFoundException ex){
//I want it to set rideCount to 0 here
//I want it to call up onCreate2 and pass rideCount to it
}}
Run Code Online (Sandbox Code Playgroud)
.
public void onBackPressed(int[] rideCount, File file) {
try {
PrintWriter output = new PrintWriter(file);
output.println(rideCount);
output.close();
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Admob 在我的应用中投放广告。
但是,它一直说“缺少必需的 XML 属性“adSize””,即使该属性在我的 XML 文件中。
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY UNIT ID"
ads:adSize="BANNER"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会这样?
干杯。