我几年没有做异常处理,我似乎无法弄清楚我做错了什么.我有一个应用程序打开我的另一个应用程序,如果用户还没有其他应用程序,我希望当前的应用程序重定向到Play商店.现在如果没有安装应用程序,程序将强行关闭.我目前的代码是:
try{
Intent intent = new Intent();
PackageManager manager = getPackageManager();
intent = manager.getLaunchIntentForPackage("my.app.package");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
}
catch(ActivityNotFoundException activityNotFound){
Intent playStoreIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=my.app.package"));
startActivity(playStoreIntent);
}
Run Code Online (Sandbox Code Playgroud)
我有一种感觉,我正在做一些非常愚蠢和错误的catch功能.任何帮助将非常感激.
我刚刚开始使用 Eclipse 进行 C++ 编程,但遇到了问题。我已经安装了 MinGW。现在我有一个简单的加法程序如下:
#include <iostream>
using namespace std;
int main() {
int number1;
int number2;
int sum;
cout << "Enter first integer: ";
cin >> number1;
cout << "Enter second integer: ";
cin >> number2;
sum = number1 + number2;
cout << sum << end1;
}
Run Code Online (Sandbox Code Playgroud)
我有一个错误Symbol end1 could not be resolved并且end1 was not declared in this scope
我之前遇到过这个错误using namespace std;,我必须进行一些配置才能让 MinGW 编译器与 Eclipse 一起工作。我不明白为什么这个错误仍然出现。在某种程度上,我尝试删除end1并运行该程序,控制台只是说“信息:没有为 CTest 构建任何内容”(这是我的项目文件夹名称的名称)。任何帮助将非常感激。
编辑:“无法解决的问题已通过更改解决end1, …
我有一个ArrayList我想从中获取随机值.为此,我想到了两个简单的方法:
方法1:用于Random生成0和大小之间的随机数ArrayList,然后使用该数字arrayList.get(x)
方法2:使用arrayList.shuffle()然后arrayList.get(0).
在随机性方面,一种方法比另一种方法更好,我知道一个人不可能是真正随机的,但我希望结果尽可能随机.
编辑:我只需要一个值 ArrayList
从SDK浮动动作按钮中的示例我有一个drawable:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<ripple android:color="@color/primary_light">
<item>
<shape android:shape="oval">
<solid android:color="@color/primary" />
</shape>
</item>
</ripple>
</item>
<item>
<ripple android:color="@color/primary_light">
<item>
<shape android:shape="oval">
<solid android:color="@color/primary" />
</shape>
</item>
</ripple>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
我正在设置我的TextView背景:
android:background="@drawable/fab_background"
Run Code Online (Sandbox Code Playgroud)
有没有办法可以访问fab_background或编辑我的TextView背景本身来改变我的FAB的颜色?
我有一个简单的问题,我对随机数生成有点生疏.我想生成大的奇数整数(我使用双精度,因为我的数字可能在int范围之外)而且我无法弄清楚如何摆脱随机数生成中的小数并且数字是奇数.
现在我只有:
N = nMin + (nMax - nMin) * rand.nextDouble();
Run Code Online (Sandbox Code Playgroud)
正如我所说,nMin和nMax之间的任意随机数(带小数).任何帮助将非常感激!
我有一个2D数组,我只需要将第一行复制到另一个相同大小的数组中.这样做的最佳方式是什么?我试过这个:
public static int[][] buildCME(int[][] array){
int [][] arrayCME = new int[array.length][array[0].length];
for(int y = 1; y < array.length; y++)
{
for (int x = 0; x < 1; x++)
{
arrayCME[y][x] = array[y][x];
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这只是给我第一行的0,我假设与我的int初始化有关.我为循环创建了这个,因为我认为考虑比在正常for循环中创建if语句以考虑整个2D数组更容易.谢谢您的帮助!
我正在编写一个ATM程序,当用户输入其中一个字符串值时,程序应检查它并相应地执行一个方法.问题代码在这里:
System.out.println("PRESS");
System.out.println("(D)eposit");
System.out.println("(W)ithdraw");
System.out.println("(C)heck Account Balance");
System.out.println("(Q)uit");
System.out.println("Enter Choice: ");
String choice = scanner.nextLine();
scanner.nextLine();
if(choice == "D"){
currentCustomer.deposit();
}
else if(choice == "W"){
currentCustomer.withdraw();
}
else if(choice == "C"){
currentCustomer.checkBalance();
}
else if(choice == "Q"){
currentCustomer.quit();
}
else{
System.out.println("Invalid choice please reenter: ");
}
Run Code Online (Sandbox Code Playgroud)
如果用户输入"D",程序将跳至else语句.我知道在使用时.nextLine你必须使用两个因为返回字符,但我不确定这种情况是否属实.无论哪种方式,如果我有额外的.nextLine声明,它仍然会向前跳过.任何帮助将非常感激!
我正在写一个有...的程序ArrayList<String> s.有没有办法从中获取每个值ArrayList并将它们设置为单独的变量?例如:
String s0 = s.get(0);
String s1 = s.get(1);
String s2 = s.get(2);
.
.
.
String sn = s.get(n);
Run Code Online (Sandbox Code Playgroud)
我会知道'n'是什么,但它会根据用户输入而改变.我只是不知道如何/如果我可以根据某些数字n动态创建变量.任何帮助将非常感激!
我正在制作一个模拟纸牌游戏的程序.我有一个Card代表扑克牌的课程:
//suit types
public enum Suits{
SPADES,
CLUBS,
HEARTS,
DIAMONDS
}
//value types
public enum Values{
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE,
}
private Suits suit;
private Values value;
//Card constructor
public Card(Values value, Suits suit){
this.value = value;
this.suit = suit;
}
Run Code Online (Sandbox Code Playgroud)
在我的游戏课中,我有一个由以下List人员代表的玩家手Cards:
public List<Card> playerHand = new ArrayList<Card>();
Run Code Online (Sandbox Code Playgroud)
有没有办法可以通过我的枚举对玩家进行排序Values?意味着如果球员的手是:
十,ACE,两个,五个
订购后会是:
两个,五个,十个,ACE
我的条件Ace总是很高,Suit并不重要.我知道订购列表是微不足道的我只是不知道如何做一个Object基于enum
我知道已有线程,但我找不到符合我需求的答案.我正在尝试使用外部JS来更改外部CSS.我有一个非常简单的CSS体型:
html, body{
background-color: black;
color: white;
}
Run Code Online (Sandbox Code Playgroud)
要使用JavaScript更改此功能,我尝试了:
var bg = document.getElementById("body");
body.style.backgroundColor = white;
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我没有太多的CSS结合JavaScript的经验,所以我觉得修复很简单,但我似乎无法找到答案.任何帮助,将不胜感激.