[英]Java code not starting new activity in Android Studio? Is it to do with the context?
[英]Java code to send Android App to new activity?
嗨,我在Android應用程序中使用http編寫了一些Java代碼,如果電視響應等於“ User Found”,我想將其發送到新活動。 這是這段代碼:
tv.setText(""+response);
if(response.equalsIgnoreCase("User Found")){
startActivity(new Intent(MainActivity.this.UserPage.class));
}
我的錯誤是針對行:
if(response.equalsIgnoreCase("User Found"))
//未為類型HttpResponse
定義equalsIgnoreCase(String)
方法,但我認為這是Http中已經存在的方法,我嘗試過忽略並只是response.("User Found")
還有我的另一個錯誤:
startActivity(new Intent(MainActivity.this.UserPage.class));
//令牌“類”上的語法錯誤,應該是標識符,我知道Java標識符不應該是關鍵字,但是如果我將class更改為MyClass或其他任何東西,或者只是將其刪除,則會遇到更多錯誤。 謝謝!
equalsIgnoreCase(String)
是String
類的方法。 您需要先將HttpResponse
轉換為String
。
使用,
而不是第二.
: startActivity(new Intent(MainActivity.this, UserPage.class));
,假設UserPage
是Activity
的子類。
My errors are for line: if(response.equalsIgnoreCase("User Found"))
//The method equalsIgnoreCase(String) is undefined for the type HttpResponse,
but I thought this was a method already in Http, I've tried ignore and
just response.("User Found")
您應該首先解析您的響應,然后再進行比較。
And my other error: startActivity(new Intent(MainActivity.this.UserPage.class));
//Syntax error on token "class", Identifier expected, I know that Java
identifiers
should not be keywords, but if I change class to MyClass or anything else, or
just delete it I get more errors. Thanks!
startActivity(new Intent(MainActivity.this,UserPage.class))[代替“。” 您應該使用“,”-我以為UserPage.class是您的第二個Activity]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.