我无法打开我的申请。据我所知,它是第一次出现我创建一个新类(现在它被删除)。即使我删除//referencje
下面的所有内容以及与它们相关的部分布局,也会出现错误。该类的名称已经过编辑,但之后就已经开始工作了。
09-12 18:56:25.512: E/AndroidRuntime(616): FATAL EXCEPTION: main
09-12 18:56:25.512: E/AndroidRuntime(616): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.test2/com.example.test2.activity_main}: java.lang.ClassNotFoundException: com.example.test2.activity_main
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.os.Handler.dispatchMessage(Handler.java:99)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.os.Looper.loop(Looper.java:137)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-12 18:56:25.512: E/AndroidRuntime(616): at java.lang.reflect.Method.invokeNative(Native Method)
09-12 18:56:25.512: E/AndroidRuntime(616): at java.lang.reflect.Method.invoke(Method.java:511)
09-12 18:56:25.512: E/AndroidRuntime(616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-12 18:56:25.512: E/AndroidRuntime(616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-12 18:56:25.512: E/AndroidRuntime(616): at dalvik.system.NativeStart.main(Native Method)
09-12 18:56:25.512: E/AndroidRuntime(616): Caused by: java.lang.ClassNotFoundException: com.example.test2.activity_main
09-12 18:56:25.512: E/AndroidRuntime(616): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-12 18:56:25.512: E/AndroidRuntime(616): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-12 18:56:25.512: E/AndroidRuntime(616): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-12 18:56:25.512: E/AndroidRuntime(616): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-12 18:56:25.512: E/AndroidRuntime(616): ... 11 more
Funkcja.java
package com.example.test2;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Funkcja extends Activity {
TextView wynik;
Button przelicz;
EditText wspXa, wspXb, wspYa, wspYb;
double n1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//referencje
wynik = (TextView) findViewById(R.id.wynik);
przelicz = (Button) findViewById(R.id.przelicz);
wspXa = (EditText) findViewById(R.id.wspXa);
wspYa = (EditText) findViewById(R.id.wspYa);
wspXb = (EditText) findViewById(R.id.wspXb);
wspYb = (EditText) findViewById(R.id.wspYb);
//Hiding status bar
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
actionBar.hide();
przelicz.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
try{
if(wspXa!=null){
double n1 = Double.parseDouble(wspXa.getText().toString());
if (n1!=0){
String total = Double.toString(n1);
wynik.setText(total);
}
}
}
catch(Exception e){
Toast.makeText(getBaseContext(), "Bledne dane", Toast.LENGTH_LONG).show();
}
}
});
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activity_main"
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>
布局:
<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="activity_main" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/literaA"
android:layout_alignLeft="@+id/literaA" />
<EditText
android:id="@+id/wspYa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/literaB"
android:layout_toRightOf="@+id/przelicz"
android:ems="10"
android:inputType="numberDecimal"
android:width="50dp" />
<EditText
android:id="@+id/wspYb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/wspXb"
android:layout_alignBottom="@+id/wspXb"
android:layout_alignLeft="@+id/wspYa"
android:ems="10"
android:inputType="numberDecimal"
android:width="50dp" />
<TextView
android:id="@+id/ywynik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/przelicz"
android:layout_marginRight="33dp"
android:layout_marginTop="24dp"
android:layout_toLeftOf="@+id/wynik"
android:text="y="
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/przelicz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/wspXb"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Przelicz" />
<EditText
android:id="@+id/wspXa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/literaB"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="numberDecimal"
android:width="50dp" />
<EditText
android:id="@+id/wspXb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/literaB"
android:layout_alignLeft="@+id/wspXa"
android:ems="10"
android:inputType="numberDecimal"
android:width="50dp" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/literaB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/literaA"
android:layout_marginRight="18dp"
android:layout_marginTop="33dp"
android:layout_toLeftOf="@+id/przelicz"
android:text="Punkt B:"
android:textSize="20sp" />
<TextView
android:id="@+id/literaA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/literaB"
android:layout_alignParentTop="true"
android:layout_marginTop="56dp"
android:text="Punkt A:"
android:textSize="20sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/wspXa"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:text="X"
android:textSize="22sp" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignLeft="@+id/wspYa"
android:layout_marginLeft="16dp"
android:text="Y"
android:textSize="22sp" />
<TextView
android:id="@+id/wynik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/ywynik"
android:layout_alignRight="@+id/wspYb"
android:layout_alignTop="@+id/ywynik"
android:layout_toRightOf="@+id/literaA"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
答案 0 :(得分:1)
您的清单的活动的Java类名称为activity_main
。将其更改为Funkcja
,这是您活动的实际Java类名称。
答案 1 :(得分:0)
在您的清单中,您的主要活动名称为:
android:name=".activity_main"
将其更改为:
android:name=".Funkcja"