在尝试添加两个数字的第一个Android应用程序时,我得到以下错误。此外,这些错误出现在AVD上的"不幸的adder_test已经停止"的错误。我已经参考了类似的帖子,但我的问题没有得到任何线索。
06-05 14:01:18.850: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:18.860: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:18.860: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:18.860: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:18.860: E/SurfaceFlinger(51): glCheckFramebufferStatusOES error -450085546
06-05 14:01:18.860: E/SurfaceFlinger(51): got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
06-05 14:01:18.860: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:18.860: E/libEGL(51): called unimplemented OpenGL ES API
06-05 14:01:22.400: E/AndroidRuntime(1493): FATAL EXCEPTION: main
06-05 14:01:22.400: E/AndroidRuntime(1493): Process: com.example.adder_test, PID: 1493
06-05 14:01:22.400: E/AndroidRuntime(1493): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.adder_test/com.example.adder_test.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.adder_test.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.adder_test-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.adder_test-1, /system/lib]]
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.os.Handler.dispatchMessage(Handler.java:102)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.os.Looper.loop(Looper.java:136)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-05 14:01:22.400: E/AndroidRuntime(1493): at java.lang.reflect.Method.invokeNative(Native Method)
06-05 14:01:22.400: E/AndroidRuntime(1493): at java.lang.reflect.Method.invoke(Method.java:515)
06-05 14:01:22.400: E/AndroidRuntime(1493): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-05 14:01:22.400: E/AndroidRuntime(1493): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-05 14:01:22.400: E/AndroidRuntime(1493): at dalvik.system.NativeStart.main(Native Method)
06-05 14:01:22.400: E/AndroidRuntime(1493): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.adder_test.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.adder_test-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.adder_test-1, /system/lib]]
06-05 14:01:22.400: E/AndroidRuntime(1493): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
06-05 14:01:22.400: E/AndroidRuntime(1493): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
06-05 14:01:22.400: E/AndroidRuntime(1493): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
06-05 14:01:22.400: E/AndroidRuntime(1493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
06-05 14:01:22.400: E/AndroidRuntime(1493): ... 11 more
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adder_test"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
<uses-sdk android:targetSdkVersion="19" android:minSdkVersion="8"></uses-sdk>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java:
import com.example.adder_test.R;
import android.app.Activity;
import android.os.Bundle;
//import android.support.v7.appcompat.R;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
Button button1;
EditText txtbox1,txtbox2;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtbox1= (EditText) findViewById(R.id.txtbox1);
button1 = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.lbl1);
txtbox2= (EditText) findViewById(R.id.txtbox2);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String a,b;
Integer vis;
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
vis = Integer.parseInt(a)+Integer.parseInt(b);
tv.setText(vis.toString());
}
}
}
感谢提供的包名。
您的问题是源文件不在清单中承诺的包中。清单承诺com.example。所以你需要提供com.example.adder_test.MainActivity.java
好运。