2014-01-27 93 views
0

我的应用程序名称是timepass 下面的文件是MainActivity.java不幸的是[应用程序名称]已停止

package com.example.timepass; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 



public class MainActivity extends Activity 
{ 
int counter; 
Button add, sub; 
TextView Display; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
counter=0; 
add= (Button) findViewById(R.id.badd); 
sub=(Button) findViewById(R.id.bsub); 
Display=(TextView) findViewById(R.id.tvdisplay); 
add.setOnClickListener(new View.OnClickListener() { 

@Override 
public void onClick(View v) { 
// TODO Auto-generated method stub 
counter++; 
Display.setText("Your total is " + counter); 

    } 
}); 

sub.setOnClickListener(new View.OnClickListener() { 

@Override 
public void onClick(View v) { 
// TODO Auto-generated method stub 
counter--; 
Display.setText("Your total is " + counter); 
} 
}); 


} 

@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; 
} 

} 

下面的文件是activity_main.xml中被realted上述文件MainActivity.java

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" 
android:background="@drawable/pic_two">" 

<Button 
android:id="@+id/badd" 
android:layout_width="100dp" 
android:layout_height="wrap_content" 
android:layout_alignLeft="@+id/tvdisplay" 
android:layout_alignTop="@+id/bsub" 
android:text="@string/but1" 
android:textSize="20sp" /> 

<TextView 
android:id="@+id/textView2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignLeft="@+id/tvdisplay" 
android:layout_alignRight="@+id/tvdisplay" 
android:text="@string/hello_world" 
android:textSize="@dimen/asa" /> 

<TextView 
android:id="@+id/tvdisplay" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_below="@+id/textView2" 
android:layout_centerHorizontal="true" 
android:layout_marginTop="42dp" 
android:gravity="center" 
android:text="@string/str1" 
android:textColor="@layout/activity_main" 
android:textSize="30sp" /> 

<Button 
android:id="@+id/bsub" 
android:layout_width="100dp" 
android:layout_height="wrap_content" 
android:layout_alignRight="@+id/tvdisplay" 
android:layout_below="@+id/tvdisplay" 
android:layout_marginRight="38dp" 
android:layout_marginTop="23dp" 
android:text="@string/but2" 
android:textSize="20sp" /> 
</RelativeLayout> 

然后,我已经创建另一个活动其低于其Splash.java

package com.example.timepass; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class Splash extends Activity 
{ 

@Override 
protected void onCreate(Bundle tpsavedInstanceState) 
{ 
// TODO Auto-generated method stub 
super.onCreate(tpsavedInstanceState); 
setContentView(R.layout.splash); 

Thread timer =new Thread() 
{  
public void run() 
{    
try 
{ 

sleep(5000); 
} 
catch(InterruptedException e) 
{ { 
e.printStackTrace(); 

} 
finally 
{ 
Intent openMainActivity =new Intent("com.example.timepass.MAINACTIVITY"); 
startActivity(openMainActivity); 
} 
} 
}; 

timer.start(); 
} 

} 

相关Splash.java然后,我已经创建的XML文件,该文件是splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"  
android:background="@drawable/pic_background"> 
</LinearLayout> 

现在我想先运行Splash.java文件,然后MainActivity.java文件,所以我必须做Androidmanifest.xml文件 中的一些更改是这些更改,并且在运行我的程序后,我收到错误“可惜timepass已停止”,其中timepass是我的应用程序名称。请解决这个问题

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.timepass" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
android:minSdkVersion="8" 
android:targetSdkVersion="18" /> 

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 

<activity 
android:name="com.example.timepass.Splash" 
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.timepass.MainActivity" 
android:label="@string/app_name" > 
<intent-filter> 
<action android:name="com.example.timepass.MAINACTIVITY" /> 
<category android:name="android.intent.category.DEFAULT" /> 
</intent-filter> 
</activity> 

</application> 
</manifest> 
+3

发布带有错误的logcat字符串 –

+0

看,我知道你是Android开发新手,这就是为什么我向你提出这个建议:你可以随时在Eclipse中查看Logcat中崩溃的原因。请学习如何通过它,然后你将面临更少的问题。截至目前,只需发布​​错误日志,我会帮助你。 – rahulritesh

回答

1

//只是做了这样的

Intent openMainActivity =new Intent(this,MainActivity.class); 
startActivity(openMainActivity); 

,而不是在你的清单

Intent openMainActivity =new Intent("com.example.timepass.MAINACTIVITY"); 
startActivity(openMainActivity); 
0

MainActivity使用在两个地方。在一个地方它是完全大写字母。改变并试一试

0

你在Splash.java中有一个额外的{e.printStackTrace();之前。删除,你会很好去。 也在日志中记录未来的错误

+1

我只是想知道他是如何能够编译它的错误持续;我希望Eclipse能够立即抛出错误! – rahulritesh

+0

我也是这样认为的,但是当eclipse忽略了日志中的错误并编译时,它发生在我身上。 – Aashir

0

我已编辑您的AndroidManifest.xml在应用程序正常工作后更新您的代码。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.timepass" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
android:minSdkVersion="8" 
android:targetSdkVersion="18" /> 

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 

<activity 
android:name="com.example.timepass.Splash" 
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.timepass.MainActivity" 
android:label="@string/app_name" > 
</activity> 

</application> 
</manifest> 

改变您的代码在splash.java

意图I =新意图(splash.this,MainActivity.class); startActivity(i);

相关问题