安卓新手上路,求问各路大神ava.lang.ClassNotFoundException与java.lang.RuntimeException是什么原因

sinat_23870319 2015-09-09 02:29:30
小弟刚刚才开始学java与安卓,这次老师布置的作业发现编译能通过,但是不能运行。logcat一看是这样的

好吧,当时我的内心是崩溃的
然后开始着手解决,但是发现那几个Exception都没办法独立解决。。无奈之下,只好来这里请教各位大神,还希望各位不吝赐教Orz
这是Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.stopwatch"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".StopWatch"
android:label="StopWatch by XGW">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:label="Stopped">
</activity>
</application>
</manifest>


import com.example.stopwatch.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.*;


public class StopWatch extends Activity{
final Calendar cal = Calendar.getInstance();
int seconds;
long startTime, t2;
boolean started = false;
int second;
int minute;
ArrayList<Integer> ListOfSecond = new ArrayList<Integer>();

public String showTimeCount(long time) {
String timeCount = "";
long hourc = time/3600000;
String hour = "0" + hourc;
hour = hour.substring(hour.length()-2, hour.length());

long minuec = (time-hourc*3600000)/(60000);
String minue = "0" + minuec;
minue = minue.substring(minue.length()-2, minue.length());

long secc = (time-hourc*3600000-minuec*60000)/1000;
String sec = "0" + secc;
sec = sec.substring(sec.length()-2, sec.length());
timeCount = hour + ":" + minue + ":" + sec;
return timeCount;
}

class Timer extends Thread{
String temp;
long startTime;
Timer(long time){
startTime = time;
}
public void run(){
try{
while(true){
cal.setTime(new Date());
long currentTime = cal.getTimeInMillis();
temp = showTimeCount(currentTime - startTime);
text.setText(temp);
Thread.sleep(1000);
}
}
catch(Exception e){
e.printStackTrace();
}
}
}

Button button1;
Button button2;
Button button3;
TextView text;

protected void onCreat(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.first_layout);

button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
text = (TextView) findViewById(R.id.textView1);
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
if(started == false){
cal.setTime(new Date());
startTime = cal.getTimeInMillis();
started = true;
Timer timer = new Timer(startTime);
timer.start();

}
else {
Toast.makeText(getBaseContext(), "you have already started it!", Toast.LENGTH_LONG).show();
}
}
});
Log.e("1","1");
button2.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cal.setTime(new Date());
long t2= cal.getTimeInMillis();
seconds = (int) ((t2 - startTime) % 1000);
ListOfSecond.add(seconds);
Toast.makeText(getBaseContext(), "time recorded.", Toast.LENGTH_SHORT).show();
}
});

button3.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "stopped.", Toast.LENGTH_LONG).show();
Bundle data = new Bundle();
Intent intent = new Intent(StopWatch.this, SecondActivity.class);
data.putIntegerArrayList("second",ListOfSecond);
intent.putExtras(data);
startActivity(intent);
}

});


}
}


import java.util.ArrayList;
import java.util.Date;
import android.util.Log;
import com.example.stopwatch.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class SecondActivity extends Activity{
public String showTimeCount(long time) {

String timeCount = "";
long hourc = time/3600;
String hour = "0" + hourc;
hour = hour.substring(hour.length()-2, hour.length());

long minuec = (time-hourc*3600);
String minue = "0" + minuec;
minue = minue.substring(minue.length()-2, minue.length());

long secc = (time-hourc*3600-minuec*60);
String sec = "0" + secc;
sec = sec.substring(sec.length()-2, sec.length());
timeCount = hour + ":" + minue + ":" + sec;
return timeCount;
}

TextView text;
Button button1;

protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.second_layout);
text = (TextView) findViewById(R.id.textView1);
button1 = (Button) findViewById(R.id.button1);
Bundle bundle = this.getIntent().getExtras();
ArrayList<Integer> ListOfSecond = bundle.getIntegerArrayList("second");
String display = "";
for (int i= 0; i < ListOfSecond.size(); ++ i){
display += showTimeCount(ListOfSecond.get(i));
display += '\n';
}

text.setText(display);

button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(SecondActivity.this, StopWatch.class);
startActivity(intent);
}
});
}
}

这是两个活动。可能写的比较渣还请各位大神轻吐
...全文
259 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinat_23870319 2015-09-09
  • 打赏
  • 举报
回复
现在已经成功解决了这个error,可以启动程序了。原来是包文件路径的问题Orz。
但现在启动之后变成了这样,加载不出layout……
qq_25039477 2015-09-09
  • 打赏
  • 举报
回复
报错的说的是你的方法没找到 你的页面注册了吗?
sinat_23870319 2015-09-09
  • 打赏
  • 举报
回复
引用 3 楼 a1129963143 的回复:
[quote=引用 楼主 sinat_23870319 的回复:] 小弟刚刚才开始学java与安卓,这次老师布置的作业发现编译能通过,但是不能运行。logcat一看是这样的 好吧,当时我的内心是崩溃的 然后开始着手解决,但是发现那几个Exception都没办法独立解决。。无奈之下,只好来这里请教各位大神,还希望各位不吝赐教Orz 这是Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.stopwatch"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity 
            android:name=".StopWatch"
            android:label="StopWatch by XGW">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity" 
            		android:label="Stopped">
        </activity>
    </application>
</manifest>
import com.example.stopwatch.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.*;


public class StopWatch extends Activity{
	final Calendar cal = Calendar.getInstance();
	int seconds;
	long startTime, t2;
	boolean started = false;
	int second;
	int minute;
	ArrayList<Integer> ListOfSecond = new ArrayList<Integer>();
	
	public String showTimeCount(long time) {
		String timeCount = "";
	    long hourc = time/3600000;
	    String hour = "0" + hourc;
	    hour = hour.substring(hour.length()-2, hour.length());
	        
	    long minuec = (time-hourc*3600000)/(60000);
	    String minue = "0" + minuec;
	    minue = minue.substring(minue.length()-2, minue.length());
	        
	    long secc = (time-hourc*3600000-minuec*60000)/1000;
	    String sec = "0" + secc;
	    sec = sec.substring(sec.length()-2, sec.length());
	    timeCount = hour + ":" + minue + ":" + sec;
	    return timeCount;
	}
	
	class Timer extends Thread{
		String temp;
		long startTime;
		Timer(long time){
			startTime = time;
		}
		public void run(){
			try{
				while(true){
					cal.setTime(new Date());
					long currentTime = cal.getTimeInMillis();
					temp = showTimeCount(currentTime - startTime);
					text.setText(temp);
					Thread.sleep(1000);
				}
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	 
	Button button1;
	Button button2;
	Button button3;
	TextView text;
	
	protected void onCreat(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first_layout);
		
		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);
		button3 = (Button) findViewById(R.id.button3);
		text = (TextView) findViewById(R.id.textView1);
		button1.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				if(started == false){
					cal.setTime(new Date());
					startTime = cal.getTimeInMillis();
					started = true;
					Timer timer = new Timer(startTime);
					timer.start();
					
				}
				else {
					Toast.makeText(getBaseContext(), "you have already started it!", Toast.LENGTH_LONG).show();
				}
			}		
		});
		Log.e("1","1");
		button2.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
			// TODO Auto-generated method stub
			cal.setTime(new Date());
		    long t2= cal.getTimeInMillis();
		    seconds = (int) ((t2 - startTime) % 1000);
		    ListOfSecond.add(seconds);
		    Toast.makeText(getBaseContext(), "time recorded.", Toast.LENGTH_SHORT).show();
			}
		});
		
		button3.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Toast.makeText(getBaseContext(), "stopped.", Toast.LENGTH_LONG).show();
				Bundle data = new Bundle();
				Intent intent = new Intent(StopWatch.this, SecondActivity.class);
				data.putIntegerArrayList("second",ListOfSecond);
				intent.putExtras(data);
				startActivity(intent);
				}
					
		});
		
		
	}
}

import java.util.ArrayList;
import java.util.Date;
import android.util.Log;
import com.example.stopwatch.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class SecondActivity extends Activity{
	public String showTimeCount(long time) {
		
		String timeCount = "";
	    long hourc = time/3600;
	    String hour = "0" + hourc;
	    hour = hour.substring(hour.length()-2, hour.length());
	        
	    long minuec = (time-hourc*3600);
	    String minue = "0" + minuec;
	    minue = minue.substring(minue.length()-2, minue.length());
	        
	    long secc = (time-hourc*3600-minuec*60);
	    String sec = "0" + secc;
	    sec = sec.substring(sec.length()-2, sec.length());
	    timeCount = hour + ":" + minue + ":" + sec;
	    return timeCount;
	}
	
	TextView text;
	Button button1;
	
	protected void onCreate(Bundle saveInstanceState){
		super.onCreate(saveInstanceState);
		setContentView(R.layout.second_layout);
		text = (TextView) findViewById(R.id.textView1);
		button1 = (Button) findViewById(R.id.button1);
		Bundle bundle = this.getIntent().getExtras();   
		ArrayList<Integer> ListOfSecond  = bundle.getIntegerArrayList("second");
		String display = "";
		for (int i= 0; i < ListOfSecond.size(); ++ i){
			display += showTimeCount(ListOfSecond.get(i));
			display += '\n';
		}
		
		text.setText(display);
	
		button1.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v) {
			Intent intent = new Intent(SecondActivity.this, StopWatch.class);
			startActivity(intent);
		}		
		});
	}
}
这是两个活动。可能写的比较渣还请各位大神轻吐
首先,作为新手还是要养成写注释的习惯啊[/quote]嗯嗯好的,小弟记住了T_T
sinat_23870319 2015-09-09
  • 打赏
  • 举报
回复
引用 5 楼 hjywyj 的回复:
package 呢?

在这里额
sinat_23870319 2015-09-09
  • 打赏
  • 举报
回复
用的是默认包额,只有一个包
  • 打赏
  • 举报
回复
package 呢?
淡的微笑 2015-09-09
  • 打赏
  • 举报
回复
异常信息不完整,还有,你没打断点调试一下吗
淡的微笑 2015-09-09
  • 打赏
  • 举报
回复
引用 楼主 sinat_23870319 的回复:
小弟刚刚才开始学java与安卓,这次老师布置的作业发现编译能通过,但是不能运行。logcat一看是这样的 好吧,当时我的内心是崩溃的 然后开始着手解决,但是发现那几个Exception都没办法独立解决。。无奈之下,只好来这里请教各位大神,还希望各位不吝赐教Orz 这是Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.stopwatch"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity 
            android:name=".StopWatch"
            android:label="StopWatch by XGW">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity" 
            		android:label="Stopped">
        </activity>
    </application>
</manifest>
import com.example.stopwatch.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.util.*;


public class StopWatch extends Activity{
	final Calendar cal = Calendar.getInstance();
	int seconds;
	long startTime, t2;
	boolean started = false;
	int second;
	int minute;
	ArrayList<Integer> ListOfSecond = new ArrayList<Integer>();
	
	public String showTimeCount(long time) {
		String timeCount = "";
	    long hourc = time/3600000;
	    String hour = "0" + hourc;
	    hour = hour.substring(hour.length()-2, hour.length());
	        
	    long minuec = (time-hourc*3600000)/(60000);
	    String minue = "0" + minuec;
	    minue = minue.substring(minue.length()-2, minue.length());
	        
	    long secc = (time-hourc*3600000-minuec*60000)/1000;
	    String sec = "0" + secc;
	    sec = sec.substring(sec.length()-2, sec.length());
	    timeCount = hour + ":" + minue + ":" + sec;
	    return timeCount;
	}
	
	class Timer extends Thread{
		String temp;
		long startTime;
		Timer(long time){
			startTime = time;
		}
		public void run(){
			try{
				while(true){
					cal.setTime(new Date());
					long currentTime = cal.getTimeInMillis();
					temp = showTimeCount(currentTime - startTime);
					text.setText(temp);
					Thread.sleep(1000);
				}
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}
	}
	 
	Button button1;
	Button button2;
	Button button3;
	TextView text;
	
	protected void onCreat(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first_layout);
		
		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);
		button3 = (Button) findViewById(R.id.button3);
		text = (TextView) findViewById(R.id.textView1);
		button1.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				if(started == false){
					cal.setTime(new Date());
					startTime = cal.getTimeInMillis();
					started = true;
					Timer timer = new Timer(startTime);
					timer.start();
					
				}
				else {
					Toast.makeText(getBaseContext(), "you have already started it!", Toast.LENGTH_LONG).show();
				}
			}		
		});
		Log.e("1","1");
		button2.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
			// TODO Auto-generated method stub
			cal.setTime(new Date());
		    long t2= cal.getTimeInMillis();
		    seconds = (int) ((t2 - startTime) % 1000);
		    ListOfSecond.add(seconds);
		    Toast.makeText(getBaseContext(), "time recorded.", Toast.LENGTH_SHORT).show();
			}
		});
		
		button3.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Toast.makeText(getBaseContext(), "stopped.", Toast.LENGTH_LONG).show();
				Bundle data = new Bundle();
				Intent intent = new Intent(StopWatch.this, SecondActivity.class);
				data.putIntegerArrayList("second",ListOfSecond);
				intent.putExtras(data);
				startActivity(intent);
				}
					
		});
		
		
	}
}

import java.util.ArrayList;
import java.util.Date;
import android.util.Log;
import com.example.stopwatch.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class SecondActivity extends Activity{
	public String showTimeCount(long time) {
		
		String timeCount = "";
	    long hourc = time/3600;
	    String hour = "0" + hourc;
	    hour = hour.substring(hour.length()-2, hour.length());
	        
	    long minuec = (time-hourc*3600);
	    String minue = "0" + minuec;
	    minue = minue.substring(minue.length()-2, minue.length());
	        
	    long secc = (time-hourc*3600-minuec*60);
	    String sec = "0" + secc;
	    sec = sec.substring(sec.length()-2, sec.length());
	    timeCount = hour + ":" + minue + ":" + sec;
	    return timeCount;
	}
	
	TextView text;
	Button button1;
	
	protected void onCreate(Bundle saveInstanceState){
		super.onCreate(saveInstanceState);
		setContentView(R.layout.second_layout);
		text = (TextView) findViewById(R.id.textView1);
		button1 = (Button) findViewById(R.id.button1);
		Bundle bundle = this.getIntent().getExtras();   
		ArrayList<Integer> ListOfSecond  = bundle.getIntegerArrayList("second");
		String display = "";
		for (int i= 0; i < ListOfSecond.size(); ++ i){
			display += showTimeCount(ListOfSecond.get(i));
			display += '\n';
		}
		
		text.setText(display);
	
		button1.setOnClickListener(new OnClickListener(){
		@Override
		public void onClick(View v) {
			Intent intent = new Intent(SecondActivity.this, StopWatch.class);
			startActivity(intent);
		}		
		});
	}
}
这是两个活动。可能写的比较渣还请各位大神轻吐
首先,作为新手还是要养成写注释的习惯啊
淡的微笑 2015-09-09
  • 打赏
  • 举报
回复
没找到类异常,触发上级的运行时异常
sinat_23870319 2015-09-09
  • 打赏
  • 举报
回复
啊对了,这个作业是要写一个秒表,也是我第一个安卓项目= = 烦请各路大神不吝赐教

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧