使用按钮开始新活动(Starting new activity via using button)
我有一个关于通过使用按钮开始新活动的问题。
我已经检查了以前与我的问题相关的问题,其中一个问题几乎相同,但解决方案对我来说没有用。 所以这是我的问题。
我有2个活动,一个叫做Acilis,第二个是MainActivity,
因此,当应用程序启动时,Acilis.class启动,并且有两个按钮,它假设在单击按钮后启动MainActivity.class。 点击应用程序崩溃后。 这是我的代码
表现:
<activity android:name="com.example.workbench.Acilis" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.workbench.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="com.example.workbench.MAINACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Acilis.class
public class Acilis extends Activity{ Button erkek, kadin; Intent intent = new Intent("com.example.workbench.MAINACTIVITY"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.anasayfa); erkek = (Button) findViewById(R.id.button_erkek); kadin = (Button) findViewById(R.id.button_kadin); erkek.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(intent); setContentView(R.layout.activity_main); } }); kadin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(intent); setContentView(R.layout.activity_main); }
MainActivity.class
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); sayfa_no = 0; ileri = (ImageButton) findViewById(R.id.button_ileri); geri = (ImageButton) findViewById(R.id.button_geri); fav = (ImageButton) findViewById(R.id.button_fav); ileri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sayfa_no++; sayfa.setText(sayfa_no + "/100"); } }); geri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sayfa_no--; sayfa.setText(sayfa_no + "/100"); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
我已经掩盖了我的括号不用担心,Eclipse不会给出任何错误。 我认为我有语义错误。
logcat的:
06-17 10:59:41.369: E/AndroidRuntime(15450): FATAL EXCEPTION: main 06-17 10:59:41.369: E/AndroidRuntime(15450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.workbench/com.example.workbench.MainActivity}: java.lang.NullPointerException 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.access$600(ActivityThread.java:141) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.os.Handler.dispatchMessage(Handler.java:99) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.os.Looper.loop(Looper.java:137) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-17 10:59:41.369: E/AndroidRuntime(15450): at java.lang.reflect.Method.invokeNative(Native Method) 06-17 10:59:41.369: E/AndroidRuntime(15450): at java.lang.reflect.Method.invoke(Method.java:511) 06-17 10:59:41.369: E/AndroidRuntime(15450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
它的错误案例太长,贴了一些部分。
感谢你们!
I have a problem about starting a new activity via using button.
I already checked the previous questions related to mine problem, one of them is almost same but solutions didn't work out for me. So here is my problem.
I have 2 activity, one called Acilis, second MainActivity,
So when app starts, Acilis.class starts and there are two buttons there, its suppose to start MainActivity.class after a button click. After I click application crashes. Here is my code
Manifest:
<activity android:name="com.example.workbench.Acilis" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.workbench.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="com.example.workbench.MAINACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
Acilis.class
public class Acilis extends Activity{ Button erkek, kadin; Intent intent = new Intent("com.example.workbench.MAINACTIVITY"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.anasayfa); erkek = (Button) findViewById(R.id.button_erkek); kadin = (Button) findViewById(R.id.button_kadin); erkek.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(intent); setContentView(R.layout.activity_main); } }); kadin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(intent); setContentView(R.layout.activity_main); }
MainActivity.class
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); sayfa_no = 0; ileri = (ImageButton) findViewById(R.id.button_ileri); geri = (ImageButton) findViewById(R.id.button_geri); fav = (ImageButton) findViewById(R.id.button_fav); ileri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sayfa_no++; sayfa.setText(sayfa_no + "/100"); } }); geri.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sayfa_no--; sayfa.setText(sayfa_no + "/100"); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }
I already take cover of my brackets don't worry, Eclipse doestn't give any error. I got semantic error I think.
LogCat:
06-17 10:59:41.369: E/AndroidRuntime(15450): FATAL EXCEPTION: main 06-17 10:59:41.369: E/AndroidRuntime(15450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.workbench/com.example.workbench.MainActivity}: java.lang.NullPointerException 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.access$600(ActivityThread.java:141) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.os.Handler.dispatchMessage(Handler.java:99) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.os.Looper.loop(Looper.java:137) 06-17 10:59:41.369: E/AndroidRuntime(15450): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-17 10:59:41.369: E/AndroidRuntime(15450): at java.lang.reflect.Method.invokeNative(Native Method) 06-17 10:59:41.369: E/AndroidRuntime(15450): at java.lang.reflect.Method.invoke(Method.java:511) 06-17 10:59:41.369: E/AndroidRuntime(15450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
Its too long error case, posted some part.
Thank you guys!
原文:https://stackoverflow.com/questions/17145786
最满意答案
这里。 尝试这个。
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
这应该在OnLaunched的App.Xaml中
Here. Try This.
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
This should be in App.Xaml on OnLaunched
相关问答
更多-
是否可以为Windows Phone 8开发控制台模式应用程序?(Is it possible to develop a console mode application for Windows Phone 8?)[2022-05-11]
没有什么比Windows Phone的文本模式更好的了。 你必须自己模拟它。 There is nothing like a text mode for Windows Phone. You have to simulate it yourself. -
Windows Phone 8 Silverlight是Windows Phone 8上的旧版UI。WinRT XAML用于Windows应用商店应用(这些是通用应用)。 Windows Phone 8.1 Silverlight与此处解释的有点不同。 Windows Phone尽管年龄较大,但Silverlight在某些方面更好。 如果您的目标是开发一款仅针对手机的应用程序,并且没有任何用于Win8 / RT的用途,请使用Silverlight。 背景音频在WinRT中是一团糟。 语音识别与Cortana ...
-
如何 - Windows Phone 7?(How to - Windows Phone 7?)[2022-10-20]
大部分是 - 获取当前位置(cellid,mnc,mmc,lac,lat,lng) 大部分没有 - 读/写/删除/拦截SMS,CallLog,联系人,日历,文件,笔记 否 - 获取已安装的应用程序列表 是 - 使用SQLite 否 - 电子邮件和VPN配置 MOSTLY NO - 能够启用/禁用蓝牙,GPRS,无线网络 是 - 录音 是 - 加密 大多数不 - 控制手机配置文件 是 - JSON 大多数不 - 文件系统通知 MOSTLY YES - Get current location (cellid, ... -
这里。 尝试这个。 ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen; 这应该在OnLaunched的App.Xaml中 Here. Try This. ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen; This should be in App.Xaml ...
-
部署在发布模式下的应用程序在Windows Phone上崩溃(App crashing on Windows Phone when deployed in Release mode)[2022-09-22]
几个快速注释: 1.-注册按钮看起来像所有的屏幕高度,你是否试图为这个按钮指定一个高度? 就像是: Button.HeightRequest = "40"; 2.-你有没有尝试链接行为“不要链接”? Finally, my problem is resolved. Please find the solution below if you have the same problem. A step by step re-creation of the project revealed that my ap ... -
是的。 Windows Phone Silverlight 8是Windows Phone 8.1发布后给予Windows Phone 8的名称。 还有Windows Phone Silverlight 8.1和Windows Phone 8.1 。 这两者之间的区别在于Windows Phone 8.1与Windows应用商店应用兼容,而Windows Phone Silverlight 8.1不兼容。 你可以在这里了解更多关于这个: http : //msdn.microsoft.com/en-us/l ...
-
据我所知,目前无法获取此信息(SDK 14393) As far as I know, there is no way to get this information right now (SDK 14393)
-
尝试这个: public MainPage() { InitializeComponent(); SetBinding(); } void SetBinding() { List
list = new List (); list.Add("January"); list.Add("Febr ... -
Mango确实是Windows Phone 7.5更新的代号。 Windows Phone 7.5中有许多新的API和功能,它带来了一个新的SDK(版本7.1)。 针对Windows Phone 7.0 SDK的应用在7.1下工作正常,但针对Windows Phone 7.1 SDK的应用需要运行Mango更新。 Windows Phone站点列出了Windows Phone 7.5(Mango更新)中的新功能, MSDN列出了7.0 SDK和7.1 SDK之间的API更改。 Mango was indee ...
-
在Windows 10 Mobile中没有像“兼容模式”这样的概念。 有不同的仿真器和设备可用。 每个设备和模拟器都可以运行特定版本的Windows Phone /移动操作系统。 Windows Phone提供向后兼容性功能,因此您可以在Windows 10移动版上运行Windows Phone 8.1应用程序,并测试那些行为不当或功能不正常的功能。 There is no such concept like "Compatibility Mode" in Windows 10 Mobile. There ...